/**
* Calculate the cross product of two vectors.
*
* @param A The first vector.
* @param B The second vector.
* @return The cross product.
*/
FORCEINLINE FVector FVector::operator^(const FVector& V) const
{
return FVector
(
Y * V.Z - Z * V.Y,
Z * V.X - X * V.Z,
X * V.Y - Y * V.X
);
}
/**
* Calculates normalized version of vector without checking for zero length.
*
* @return Normalized version of vector.
* @see GetSafeNormal()
*/
FORCEINLINE FVector GetUnsafeNormal() const;
/**
* Gets a normalized copy of the vector, checking it is safe to do so based on the length.
* Returns zero vector if vector length is too small to safely normalize.
*
* @param Tolerance Minimum squared vector length.
* @return A normalized copy if safe, (0,0,0) otherwise.
*/
FVector GetSafeNormal(float Tolerance=SMALL_NUMBER) const;
/**
* Get a copy of this vector, clamped inside of a cube.
*
* @param Radius Half size of the cube.
* @return A copy of this vector, bound by cube.
*/
FVector BoundToCube(float Radius) const;
/** Get a copy of this vector, clamped inside of a cube. */
FVector BoundToBox(const FVector& Min, const FVector Max) const;
/** Create a copy of this vector, with its magnitude clamped between Min and Max. */
FVector GetClampedToSize(float Min, float Max) const;
/** Create a copy of this vector, with the 2D magnitude clamped between Min and Max. Z is unchanged. */
FVector GetClampedToSize2D(float Min, float Max) const;
/** Create a copy of this vector, with its maximum magnitude clamped to MaxSize. */
FVector GetClampedToMaxSize(float MaxSize) const;
/** Create a copy of this vector, with the maximum 2D magnitude clamped to MaxSize. Z is unchanged. */
FVector GetClampedToMaxSize2D(float MaxSize) const;
/**
* Add a vector to this and clamp the result in a cube.
*
* @param V Vector to add.
* @param Radius Half size of the cube.
*/
void AddBounded(const FVector& V, float Radius=MAX_int16);
/**
* Gets a copy of this vector projected onto the input vector.
*
* @param A Vector to project onto, does not assume it is normalized.
* @return Projected vector.
*/
FORCEINLINE FVector FVector::ProjectOnTo(const FVector& A) const
{
return (A * ((*this | A) / (A | A)));
}
/**
* Gets a copy of this vector projected onto the input vector, which is assumed to be unit length.
*
* @param Normal Vector to project onto (assumed to be unit length).
* @return Projected vector.
*/
FORCEINLINE FVector ProjectOnToNormal(const FVector& Normal) const;
计算一个向量在另外一个向量上面的投影。比如要将b投影到a,投影向量 c = a / |a| * |b| * cos α = a / |a| * |b| * (ab/|a||b|) = a * (ab) / (|a| * |a|)。如果是单位向量,则结果是 a * (ab)