Unreal Math: FVector2D

 
 

属性

 
 


 
 
struct FVector2D 
{
	/** Vector's X component. */
	float X;

	/** Vector's Y component. */
	float Y;
}
 
  
 
 

2D向量,两个float成员x,y,很简单。

 
  
 
 

方法

 
  
 
 

都是一些基本的操作。

 
  
 
 
向量加法
FORCEINLINE FVector2D operator+(const FVector2D& V) const; 
向量减法
FORCEINLINE FVector2D operator-(const FVector2D& V) const; 
数乘/除
FORCEINLINE FVector2D operator*(float Scale) const; 
FVector2D operator/(float Scale) const; 
向量分量+/-/*//同一个数
FORCEINLINE FVector2D operator+(float A) const;
FORCEINLINE FVector2D operator-(float A) const;
FORCEINLINE FVector2D operator*(float Scale) const;
FVector2D operator/(float Scale) const;
向量分量*//
FORCEINLINE FVector2D operator*(const FVector2D& V) const;
FVector2D operator/(const FVector2D& V) const;
向量点乘
FORCEINLINE float operator|(const FVector2D& V) const;
向量叉乘(注意结果是一个值)
FORCEINLINE float operator^(const FVector2D& V) const;
……………………………………………………………………………………………………………………………………………………………………………………………………
 
  
 
 

FVector2D GetRotated(float AngleDeg) const;

 
  
 
 

计算向量绕远点逆时针旋转后的向量,使用向量左乘旋转矩阵计算。二维旋转矩阵的形式为: $$ \left[ \begin{matrix} cos \theta & sin \theta \\ -sin \theta & cos \theta \end{matrix} \right] $$

 
  
 
 
计算单位向量,零向量返回零向量
FVector2D GetSafeNormal(float Tolerance=SMALL_NUMBER) const;
向量单位化
void Normalize(float Tolerance=SMALL_NUMBER);
 
  
 
 

void ToDirectionAndLength(FVector2D &OutDir, float &OutLength) const;

 
  
 
 

获得向量的方向向量和长度

 
  
 
 

FVector2D RoundToVector() const;

 
  
 
 

round到最近的整数点

 
  
 
 

inline FVector SphericalToUnitCartesian() const;

 
  
 
 

这个函数是指这个2D向量用来表示一个球坐标形式的3D向量,向量终点在单位球上面,x表示 θ ,y表示 φ ,r隐含是1,然后返回这个向量的直角坐标形式,其实就是球坐标转直角坐标,只是形式上面很怪。

 
  
 
 
  • x = rsinθcosφ = sinxcosy
  • y = rsinθsinφ = sinxsiny
  • z = rcosθ = cosx
 
  
 
 
 
 

猜你喜欢

转载自www.cnblogs.com/haisong1991/p/11256492.html