# FVector

Inheritance Hierarchy

Syntax

struct FVector

Remarks

A vector in 3-D space composed of components (X, Y, Z) with floating point precision.

Variables

Name Description

float

X

Vector's X component.

float

Y

Vector's Y component.

float

Z

Vector's Z component.

Constructors

Name Description

FVector()

Default constructor (no initialization).

FVector

(
float InF
)

Constructor initializing all components to a single float value.

FVector

(
const FVector4 & V
)

Constructor using the XYZ components from a 4D vector.

FVector

(
const FLinearColor & InColor
)

Constructs a vector from an FLinearColor .

FVector

(
FIntVector InVector
)

Constructs a vector from an FIntVector .

FVector

(
FIntPoint A
)

Constructs a vector from an FIntPoint .

FVector

Constructor which initializes all components to zero.

FVector

(
const FVector2D V,
float InZ
)

Constructs a vector from an FVector2D and Z value.

FVector

(
float InX,
float InY,
float InZ
)

Constructor using initial values for each component.

Functions

Name Description

void

(
const FVector & V,
)

Add a vector to this and clamp the result in a cube.

bool

AllComponentsEqual

(
float Tolerance
)

Checks whether all components of this vector are the same, within a tolerance.

BoundToBox

(
const FVector & Min,
const FVector Max
)

Get a copy of this vector, clamped inside of a cube.

BoundToCube

(
)

Get a copy of this vector, clamped inside of a cube.

float

BoxPushOut

(
const FVector & Normal,
const FVector & Size
)

Compute pushout of a box from a plane.

bool

Coincident

(
const FVector & Normal1,
const FVector & Normal2,
float ParallelCosineThreshold
)

See if two normal vectors are coincident (nearly parallel and point in the same direction).

float

Component

(
int32 Index
)

Gets a specific component of the vector.

float &

Component

(
int32 Index
)

Gets a specific component of the vector.

ComponentMax

(
const FVector & Other
)

Gets the component-wise max of two vectors.

ComponentMin

(
const FVector & Other
)

Gets the component-wise min of two vectors.

bool

ContainsNaN()

Utility to check if there are any non-finite values (NaN or Inf) in this vector.

bool

Coplanar

(
const FVector & Base1,
const FVector & Normal1,
const FVector & Base2,
const FVector & Normal2,
float ParallelCosineThreshold
)

See if two planes are coplanar.

float

CosineAngle2D

(
FVector B
)

Returns the cosine of the angle between this vector and another projected onto the XY plane (no Z).

void

CreateOrthonormalBasis

(
FVector & XAxis,
FVector & YAxis,
FVector & ZAxis
)

Create an orthonormal basis from a basis with at least two orthogonal vectors.

CrossProduct

(
const FVector & A,
const FVector & B
)

Calculate the cross product of two vectors.

(
const FVector & DegVector
)

Converts a vector containing degree values to a vector containing radian values.

void

DiagnosticCheckNaN()

void

DiagnosticCheckNaN

(
const TCHAR * Message
)

float

Dist

(
const FVector & V1,
const FVector & V2
)

Euclidean distance between two points.

float

Dist2D

(
const FVector & V1,
const FVector & V2
)

float

Distance

(
const FVector & V1,
const FVector & V2
)

float

DistSquared

(
const FVector & V1,
const FVector & V2
)

Squared distance between two points.

float

DistSquared2D

(
const FVector & V1,
const FVector & V2
)

float

DistSquaredXY

(
const FVector & V1,
const FVector & V2
)

Squared distance between two points in the XY plane only.

float

DistXY

(
const FVector & V1,
const FVector & V2
)

Euclidean distance between two points in the XY plane (ignoring Z).

float

DotProduct

(
const FVector & A,
const FVector & B
)

Calculate the dot product of two vectors.

bool

Equals

(
const FVector & V,
float Tolerance
)

Check against another vector for equality, within specified error limits.

float

EvaluateBezier

(
const FVector * ControlPoints,
int32 NumPoints,
TArray < FVector >& OutPoints
)

Generates a list of sample points on a Bezier curve defined by 2 points.

void

FindBestAxisVectors

(
FVector & Axis1,
FVector & Axis2
)

Find good arbitrary axis vectors to represent U and V axes of a plane, using this vector as the normal of the plane.

void

GenerateClusterCenters

(
TArray < FVector >& Clusters,
const TArray < FVector >& Points,
int32 NumIterations,
int32 NumConnectionsToBeValid
)

Given a current set of cluster centers, a set of points, iterate N times to move clusters to be central.

GetAbs()

Get a copy of this vector with absolute value of each component.

float

GetAbsMax()

Get the maximum absolute value of the vector's components.

float

GetAbsMin()

Get the minimum absolute value of the vector's components.

GetClampedToMaxSize

(
float MaxSize
)

Create a copy of this vector, with its maximum magnitude clamped to MaxSize.

GetClampedToMaxSize2D

(
float MaxSize
)

Create a copy of this vector, with the maximum 2D magnitude clamped to MaxSize. Z is unchanged.

GetClampedToSize

(
float Min,
float Max
)

Create a copy of this vector, with its magnitude clamped between Min and Max.

GetClampedToSize2D

(
float Min,
float Max
)

Create a copy of this vector, with the 2D magnitude clamped between Min and Max. Z is unchanged.

float

GetComponentForAxis

(
EAxis::Type Axis
)

Get a specific component of the vector, given a specific axis by enum

float

GetMax()

Get the maximum value of the vector's components.

float

GetMin()

Get the minimum value of the vector's components.

GetSafeNormal

(
float Tolerance
)

Gets a normalized copy of the vector, checking it is safe to do so based on the length.

GetSafeNormal2D

(
float Tolerance
)

Gets a normalized copy of the 2D components of the vector, checking it is safe to do so.

GetSignVector()

Get a copy of the vector as sign only.

GetUnsafeNormal()

Calculates normalized version of vector without checking for zero length.

GetUnsafeNormal2D()

Calculates normalized 2D version of vector without checking for zero length.

GridSnap

(
const float& GridSz
)

Gets a copy of this vector snapped to a grid.

float

Convert a direction vector into a 'heading' angle.

bool

InitFromString

(
const FString & InSourceString
)

Initialize this Vector based on an FString .

bool

IsNearlyZero

(
float Tolerance
)

Checks whether vector is near to zero within a specified tolerance.

bool

IsNormalized()

Checks whether vector is normalized.

bool

IsUniform

(
float Tolerance
)

Check whether X, Y and Z are nearly equal.

bool

IsUnit

(
float LengthSquaredTolerance
)

Check if the vector is of unit length, with specified tolerance.

bool

IsZero()

Checks whether all components of the vector are exactly zero.

MirrorByPlane

(
const FPlane & Plane
)

Mirrors a vector about a plane.

FVector inline functions

MirrorByVector

(
const FVector & MirrorNormal
)

Mirror a vector about a normal vector.

bool

NetSerialize

(
FArchive & Ar,
UPackageMap * Map,
bool& bOutSuccess
)

Network serialization function.

bool

Normalize

(
float Tolerance
)

Normalize this vector in-place if it is larger than a given tolerance. Leaves it unchanged if not.

bool

Orthogonal

(
const FVector & Normal1,
const FVector & Normal2,
float OrthogonalCosineThreshold
)

See if two normal vectors are nearly orthogonal (perpendicular), meaning the angle between them is close to 90 degrees.

bool

Parallel

(
const FVector & Normal1,
const FVector & Normal2,
float ParallelCosineThreshold
)

See if two normal vectors are nearly parallel, meaning the angle between them is close to 0 degrees.

float

PointPlaneDist

(
const FVector & Point,
const FVector & PlaneBase,
const FVector & PlaneNormal
)

Calculate the signed distance (in the direction of the normal) between a point and a plane.

PointPlaneProject

(
const FVector & Point,
const FVector & A,
const FVector & B,
const FVector & C
)

Calculate the projection of a point on the plane defined by counter-clockwise (CCW) points A,B,C.

PointPlaneProject

(
const FVector & Point,
const FVector & PlaneBase,
const FVector & PlaneNormal
)

Calculate the projection of a point on the plane defined by PlaneBase and PlaneNormal.

PointPlaneProject

(
const FVector & Point,
const FPlane & Plane
)

Calculate the projection of a point on the given plane.

bool

PointsAreNear

(
const FVector & Point1,
const FVector & Point2,
float Dist
)

Compare two points and see if they're within specified distance.

bool

PointsAreSame

(
const FVector & P,
const FVector & Q
)

Compare two points and see if they're the same, using a threshold.

Projection()

Projects 2D components of vector based on Z.

ProjectOnTo

(
const FVector & A
)

Gets a copy of this vector projected onto the input vector.

ProjectOnToNormal

(
const FVector & Normal
)

Gets a copy of this vector projected onto the input vector, which is assumed to be unit length.

(
)

Converts a vector containing radian values to a vector containing degree values.

Reciprocal()

Gets the reciprocal of this vector, avoiding division by zero.

RotateAngleAxis

(
const float AngleDeg,
const FVector & Axis
)

Rotates around Axis (assumes Axis.Size() == 1).

Rotation()

Return the FRotator orientation corresponding to the direction in which the vector points.

bool

Serialize

(
FArchive & Ar
)

bool

Serialize

void

Set

(
float InX,
float InY,
float InZ
)

Set the values of the vector directly.

void

SetComponentForAxis

(
EAxis::Type Axis,
float Component
)

Set a specified componet of the vector, given a specific axis by enum

float

Size()

Get the length (magnitude) of this vector.

float

Size2D()

Get the length of the 2D components of this vector.

float

SizeSquared()

Get the squared length of this vector.

float

SizeSquared2D()

Get the squared length of the 2D components of this vector.

ToCompactString()

Get a short textural representation of this vector, for compact readable logging.

ToCompactText()

Get a short locale aware textural representation of this vector, for compact readable logging.

void

ToDirectionAndLength

(
FVector & OutDir,
float& OutLength
)

Util to convert this vector into a unit direction vector and its original length.

ToOrientationQuat()

Return the Quaternion orientation corresponding to the direction in which the vector points.

ToOrientationRotator()

Return the FRotator orientation corresponding to the direction in which the vector points.

ToString()

Get a textual representation of this vector.

ToText()

Get a locale aware textual representation of this vector.

float

Triple

(
const FVector & X,
const FVector & Y,
const FVector & Z
)

Triple product of three vectors: X dot (Y cross Z).

UnitCartesianToSpherical()

Converts a Cartesian unit vector into spherical coordinates on the unit sphere.

void

UnwindEuler()

When this vector contains Euler angles (degrees), ensure that angles are between +/-180

VectorPlaneProject

(
const FVector & V,
const FVector & PlaneNormal
)

Calculate the projection of a vector on the plane defined by PlaneNormal.

Operators

Name Description

operator-()

Get a negated copy of the vector.

operator-

(
const FVector & V
)

Gets the result of component-wise subtraction of this by another vector.

operator-

(
float Bias
)

Gets the result of subtracting from each component of the vector.

bool

operator!=

(
const FVector & V
)

Check against another vector for inequality.

operator*

(
float Scale
)

Gets the result of scaling the vector (multiplying each component by a value).

operator*

(
const FVector & V
)

Gets the result of component-wise multiplication of this vector by another.

operator*=

(
float Scale
)

Scales the vector.

operator*=

(
const FVector & V
)

Multiplies the vector with another vector, using component-wise multiplication.

operator/

(
float Scale
)

Gets the result of dividing each component of the vector by a value.

operator/

(
const FVector & V
)

Gets the result of component-wise division of this vector by another.

operator/=

(
float V
)

Divides the vector by a number.

operator/=

(
const FVector & V
)

Divides the vector by another vector, using component-wise division.

float &

operator[]

(
int32 Index
)

Gets specific component of the vector.

float

operator[]

(
int32 Index
)

Gets specific component of the vector.

operator^

(
const FVector & V
)

Calculate cross product between this and another vector.

float

operator|

(
const FVector & V
)

Calculate the dot product between this and another vector.

operator+

(
const FVector & V
)

Gets the result of component-wise addition of this and another vector.

operator+

(
float Bias
)

Gets the result of adding to each component of the vector.

operator+=

(
const FVector & V
)

operator-=

(
const FVector & V
)

Subtracts another vector from this. Uses component-wise subtraction.

bool

operator==

(
const FVector & V
)

Check against another vector for equality.

Constants

Name

Description

BackwardVector

Unreal backward vector (-1,0,0)

DownVector

Unreal down vector (0,0,-1)

ForwardVector

Unreal forward vector (1,0,0)

LeftVector

Unreal left vector (0,-1,0)

OneVector

One vector (1,1,1)

RightVector

Unreal right vector (0,1,0)

UpVector

Unreal up vector (0,0,1)

ZeroVector

A zero vector (0,0,0)

Math stats

References