FMath

Structure for all math helper functions, inherits from platform math to pick up platform-specific implementations Check GenericPlatformMath.h for additional math functions

Choose your operating system:

Windows

macOS

Linux

Inheritance Hierarchy

References

Module

Core

Header

/Engine/Source/Runtime/Core/Public/Math/UnrealMathUtility.h

Include

#include "Math/UnrealMathUtility.h"

Syntax

struct FMath : public FMicrosoftPlatformMathBase

Remarks

Structure for all math helper functions, inherits from platform math to pick up platform-specific implementations Check GenericPlatformMath.h for additional math functions

Functions

Name Description

Public function Static

void

 

ApplyScaleToFloat

(
    float& Dst,
    const FVector& DeltaScale,
    float Magnitude
)

Handy to apply scaling in the editor

Public function Static

T

 

BiLerp

(
    const T& P00,
    const T& P10,
    const T& P01,
    const T& P11,
    const U& FracX,
    const U& FracY
)

Custom lerps defined for those classes not suited to the default implemenation.

Public function Static

constexpr T

 

BiLerp

(
    const T& P00,
    const T& P10,
    const T& P01,
    const T& P11,
    const U& FracX,
    const U& FracY
)

Performs a 2D linear interpolation between four values values, FracX, FracY ranges from 0-1

Public function Static

void

 

CartesianToPolar

(
    const UE::Math::TVector2< T > InCar...,
    UE::Math::TVector2< T >& OutPolar
)

Converts given Cartesian coordinate pair to Polar coordinate system.

Public function Static

void

 

CartesianToPolar

(
    const T X,
    const T Y,
    T& OutRad,
    T& OutAng
)

Converts given Cartesian coordinate pair to Polar coordinate system.

Public function Static

FLinearColor

 

CInterpTo

(
    const FLinearColor& Current,
    const FLinearColor& Target,
    float DeltaTime,
    float InterpSpeed
)

Interpolate Linear Color from Current to Target.

Public function Static

constexpr T

 

Clamp

(
    const T X,
    const T Min,
    const T Max
)

Clamps X to be between Min and Max, inclusive

Public function Static

float

 

ClampAngle

(
    float AngleDegrees,
    float MinAngleDegrees,
    float MaxAngleDegrees
)

Clamps an arbitrary angle to be between the given angles. Will clamp to nearest boundary.

Public function Static

FVector

 

ClosestPointOnInfiniteLine

(
    const FVector& LineStart,
    const FVector& LineEnd,
    const FVector& Point
)

Find the point on the infinite line between two points (LineStart, LineEnd) which is closest to Point

Public function Static

FVector

 

ClosestPointOnLine

(
    const FVector& LineStart,
    const FVector& LineEnd,
    const FVector& Point
)

Find the point on the line segment from LineStart to LineEnd which is closest to Point

Public function Static

FVector

 

ClosestPointOnSegment

(
    const FVector& Point,
    const FVector& StartPoint,
    const FVector& EndPoint
)

Returns closest point on a segment to a given point.

Public function Static

FVector2D

 

ClosestPointOnSegment2D

(
    const FVector2D& Point,
    const FVector2D& StartPoint,
    const FVector2D& EndPoint
)

FVector2D version of ClosestPointOnSegment.

Public function Static

FVector

 

ClosestPointOnTetrahedronToPoint

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

Returns closest point on a tetrahedron to a point.

Public function Static

FVector

 

ClosestPointOnTriangleToPoint

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

Returns closest point on a triangle to a point.

Public function Static

FVector

 

ComputeBaryCentric2D

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

Computes the barycentric coordinates for a given point in a triangle

Public function Static

FVector4

 

ComputeBaryCentric3D

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

Computes the barycentric coordinates for a given point on a tetrahedron (3D)

Public function Static

UE::Math::TS...

 

ComputeBoundingSphereForCone

(
    UE::Math::TVector< FReal > const& ...,
    UE::Math::TVector< FReal > const& ...,
    FReal ConeRadius,
    FReal CosConeAngle,
    FReal SinConeAngle
)

FMath inline functions Computes minimal bounding sphere encompassing given cone

Public function Static

uint32

 

ComputeProjectedSphereScissorRect

(
    FIntRect& InOutScissorRect,
    FVector SphereOrigin,
    float Radius,
    FVector ViewOrigin,
    const FMatrix& ViewMatrix,
    const FMatrix& ProjMatrix
)

InOutScissorRect should be set to View.ViewRect before the call

Public function Static

constexpr vo...

 

CriticallyDampedSmoothing

(
    T& InOutValue,
    T& InOutValueRate,
    const T& InTargetValue,
    const T& InTargetValueRate,
    const float InDeltaTime,
    const float InSmoothingTime
)

Smooths a value using a critically damped spring.

Public function Static

constexpr T

 

Cube

(
    const T A
)

Cubes the value

Public function Static

constexpr U

 

CubicCRSplineInterp

(
    const U& P0,
    const U& P1,
    const U& P2,
    const U& P3,
    const float T0,
    const float T1,
    const float T2,
    const float T3,
    const float T
)

Cubic Catmull-Rom Spline interpolation.

Public function Static

constexpr U

 

CubicCRSplineInterpSafe

(
    const U& P0,
    const U& P1,
    const U& P2,
    const U& P3,
    const float T0,
    const float T1,
    const float T2,
    const float T3,
    const float T
)

Same as CubicCRSplineInterp but with additional saftey checks. If the checks fail P1 is returned.

Public function Static

constexpr T

 

CubicInterp

(
    const T& P0,
    const T& T0,
    const T& P1,
    const T& T1,
    const U& A
)

Performs a cubic interpolation

Public function Static

T

 

CubicInterp

(
    const T& P0,
    const T& T0,
    const T& P1,
    const T& T1,
    const U& A
)

Custom lerps defined for those classes not suited to the default implemenation.

Public function Static

constexpr T

 

CubicInterpDerivative

(
    const T& P0,
    const T& T0,
    const T& P1,
    const T& T1,
    const U& A
)

Performs a first derivative cubic interpolation

Public function Static

constexpr T

 

CubicInterpSecondDerivative

(
    const T& P0,
    const T& T0,
    const T& P1,
    const T& T1,
    const U& A
)

Performs a second derivative cubic interpolation

Public function Static

constexpr au...

 

DegreesToRadians

(
    T const& DegVal
)

Converts degrees to radians.

Public function Static

double

 

DegreesToRadians

(
    double const& DegVal
)

Public function Static

float

 

DegreesToRadians

(
    float const& DegVal
)

Public function Static

constexpr T

 

DivideAndRoundDown

(
    T Dividend,
    T Divisor
)

Divides two integers and rounds down

Public function Static

constexpr T

 

DivideAndRoundNearest

(
    T Dividend,
    T Divisor
)

Divides two integers and rounds to nearest

Public function Static

constexpr T

 

DivideAndRoundUp

(
    T Dividend,
    T Divisor
)

Divides two integers and rounds up

Public function Static

T

 

DynamicWeightedMovingAverage

(
    T CurrentSample,
    T PreviousSample,
    T MaxDistance,
    T MinWeight,
    T MaxWeight
)

Calculates the new value in a weighted moving average series using the previous value and a weight range.

Public function Static

bool

 

Eval

(
    FString Str,
    float& OutValue
)

Evaluates a numerical equation.

Public function Static

constexpr vo...

 

ExponentialSmoothingApprox

(
    T& InOutValue,
    const T& InTargetValue,
    const float InDeltaTime,
    const float InSmoothingTime
)

Smooths a value using exponential damping towards a target.

Public function Static

constexpr bo...

 

ExtractBoolFromBitfield

(
    uint8* Ptr,
    uint32 Index
)

Get a bit in memory created from bitflags (uint32 Value:1), used for EngineShowFlags, TestBitFieldFunctions() tests the implementation

Public function Static

float

 

FastAsin

(
    float Value
)

Computes the ASin of a scalar value.

Public function Static

double

 

FastAsin

(
    double Value
)

Public function Static

constexpr au...

 

FindDeltaAngleDegrees

(
    T A1,
    T2 A2
)

Find the smallest angle between two headings (in degrees)

Public function Static

constexpr au...

 

FindDeltaAngleRadians

(
    T A1,
    T2 A2
)

Find the smallest angle between two headings (in radians)

Public function Static

auto

 

FInterpConstantTo

(
    T1 Current,
    T2 Target,
    T3 DeltaTime,
    T4 InterpSpeed
)

Interpolate float from Current to Target with constant step

Public function Static

auto

 

FInterpTo

(
    T1 Current,
    T2 Target,
    T3 DeltaTime,
    T4 InterpSpeed
)

Interpolate float from Current to Target.

Public function Static

float

 

FixedTurn

(
    float InCurrent,
    float InDesired,
    float InDeltaRate
)

Returns a new rotation component value

Public function Static

double

 

Floor

(
    double F
)

Converts a double to a nearest less or equal integer.

Public function Static

constexpr In...

 

Floor

(
    IntegralType I
)

Converts an integral type to a nearest less or equal integer.

Public function Static

float

 

Floor

(
    float F
)

Converts a float to a nearest less or equal integer.

Public function Static

FString

 

FormatIntToHumanReadable

(
    int32 Val
)

Formats an integer value into a human readable string (i.e. 12345 becomes "12,345")

Public function Static

float

 

FRandRange

(
    float InMin,
    float InMax
)

Util to generate a random number in a range.

Public function Static

double

 

FRandRange

(
    double InMin,
    double InMax
)

Util to generate a random number in a range.

Public function Static

FVector2D

 

GetAzimuthAndElevation

(
    const FVector& Direction,
    const FVector& AxisX,
    const FVector& AxisY,
    const FVector& AxisZ
)

Returns Azimuth and Elevation of vector 'Direction' in coordinate system O(AxisX,AxisY,AxisZ).

Public function Static

FVector

 

GetBaryCentric2D

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

Computes the barycentric coordinates for a given point in a triangle - simpler than the Compute versions

Public function Static

FVector

 

GetBaryCentric2D

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

Computes the barycentric coordinates for a given point in a triangle, only considering the XY coordinates - simpler than the Compute versions

Public function Static

bool

 

GetDistanceWithinConeSegment

(
    FVector Point,
    FVector ConeStartPoint,
    FVector ConeLine,
    float RadiusAtStart,
    float RadiusAtEnd,
    float& PercentageOut
)

Calculates whether a Point is within a cone segment, and also what percentage within the cone (100% is along the center line, whereas 0% is along the edge)

Public function Static

bool

 

GetDotDistance

(
    FVector2D& OutDotDist,
    const FVector& Direction,
    const FVector& AxisX,
    const FVector& AxisY,
    const FVector& AxisZ
)

Calculates the dotted distance of vector 'Direction' to coordinate system O(AxisX,AxisY,AxisZ).

Public function Static

auto

 

GetMappedRangeValueClamped

(
    const UE::Math::TVector2< T >& Inp...,
    const UE::Math::TVector2< T >& Out...,
    const T2 Value
)

For the given Value clamped to the [Input:Range] inclusive, returns the corresponding percentage in [Output:Range] Inclusive.

Public function Static

T

 

GetMappedRangeValueClamped

(
    const TRange< T >& InputRange,
    const TRange< T >& OutputRange,
    const T Value
)

Public function Static

auto

 

GetMappedRangeValueUnclamped

(
    const UE::Math::TVector2< T >& Inp...,
    const UE::Math::TVector2< T >& Out...,
    const T2 Value
)

Transform the given Value relative to the input range to the Output Range.

Public function Static

constexpr au...

 

GetRangePct

(
    T MinValue,
    T MaxValue,
    T2 Value
)

Calculates the percentage along a line from MinValue to MaxValue that Value is.

Public function Static

double

 

GetRangePct

(
    TRange< T > const& Range,
    T Value
)

Public function Static

auto

 

GetRangePct

(
    UE::Math::TVector2< T > const& Ran...,
    T2 Value
)

Same as above, but taking a 2d vector as the range.

Public function Static

auto

 

GetRangeValue

(
    UE::Math::TVector2< T > const& Ran...,
    T2 Pct
)

Basically a Vector2d version of Lerp.

Public function Static

T

 

GetRangeValue

(
    TRange< T > const& Range,
    T Pct
)

Public function Static

FVector

 

GetReflectionVector

(
    const FVector& Direction,
    const FVector& SurfaceNormal
)

Given a direction vector and a surface normal, returns the vector reflected across the surface normal.

Public function Static

float

 

GetTForSegmentPlaneIntersect

(
    const FVector& StartPoint,
    const FVector& EndPoint,
    const FPlane& Plane
)

Returns the time (t) of the intersection of the passed segment and a plane (could be <0 or >1)

Public function Static

constexpr in...

 

GreatestCommonDivisor

(
    int32 a,
    int32 b
)

Use the Euclidean method to find the GCD.

Public function Static

constexpr T

 

GridSnap

(
    T Location,
    T Grid
)

Snaps a value to the nearest grid multiple

Public function Static

T

 

InterpCircularIn

(
    const T& A,
    const T& B,
    float Alpha
)

Interpolation between A and B, applying a circular in function.

Public function Static

T

 

InterpCircularInOut

(
    const T& A,
    const T& B,
    float Alpha
)

Interpolation between A and B, applying a circular in/out function.

Public function Static

T

 

InterpCircularOut

(
    const T& A,
    const T& B,
    float Alpha
)

Interpolation between A and B, applying a circular out function.

Public function Static

T

 

InterpEaseIn

(
    const T& A,
    const T& B,
    float Alpha,
    float Exp
)

Interpolate between A and B, applying an ease in function. Exp controls the degree of the curve.

Public function Static

T

 

InterpEaseInOut

(
    const T& A,
    const T& B,
    float Alpha,
    float Exp
)

Interpolate between A and B, applying an ease in/out function.

Public function Static

T

 

InterpEaseOut

(
    const T& A,
    const T& B,
    float Alpha,
    float Exp
)

Interpolate between A and B, applying an ease out function. Exp controls the degree of the curve.

Public function Static

T

 

InterpExpoIn

(
    const T& A,
    const T& B,
    float Alpha
)

Interpolation between A and B, applying an exponential in function.

Public function Static

T

 

InterpExpoInOut

(
    const T& A,
    const T& B,
    float Alpha
)

Interpolation between A and B, applying an exponential in/out function.

Public function Static

T

 

InterpExpoOut

(
    const T& A,
    const T& B,
    float Alpha
)

Interpolation between A and B, applying an exponential out function.

Public function Static

T

 

InterpSinIn

(
    const T& A,
    const T& B,
    float Alpha
)

Interpolation between A and B, applying a sinusoidal in function.

Public function Static

T

 

InterpSinInOut

(
    const T& A,
    const T& B,
    float Alpha
)

Interpolation between A and B, applying a sinusoidal in/out function.

Public function Static

T

 

InterpSinOut

(
    const T& A,
    const T& B,
    float Alpha
)

Interpolation between A and B, applying a sinusoidal out function.

Public function Static

constexpr T

 

InterpStep

(
    const T& A,
    const T& B,
    float Alpha,
    int32 Steps
)

Interpolation between A and B, applying a step function.

Public function

bool

 

IntersectPlanes2

(
    UE::Math::TVector< T >& I,
    UE::Math::TVector< T >& D,
    const UE::Math::TPlane< T >& P1,
    const UE::Math::TPlane< T >& P2
)

Public function Static

bool

 

IntersectPlanes2

(
    UE::Math::TVector< FReal >& I,
    UE::Math::TVector< FReal >& D,
    const UE::Math::TPlane< FReal >& P...,
    const UE::Math::TPlane< FReal >& P...
)

Compute intersection point and direction of line joining two planes.

Public function

bool

 

IntersectPlanes3

(
    UE::Math::TVector< T >& I,
    const UE::Math::TPlane< T >& P1,
    const UE::Math::TPlane< T >& P2,
    const UE::Math::TPlane< T >& P3
)

Public function Static

bool

 

IntersectPlanes3

(
    UE::Math::TVector< FReal >& I,
    const UE::Math::TPlane< FReal >& P...,
    const UE::Math::TPlane< FReal >& P...,
    const UE::Math::TPlane< FReal >& P...
)

Compute intersection point of three planes. Return 1 if valid, 0 if infinite.

Public function Static

constexpr T

 

InvExpApprox

(
    T X
)

Returns an approximation of Exp(-X) based on a Taylor expansion that has had the coefficients adjusted (using optimisation) to minimise the error in the range 0 < X < 1, which is below 0.1%.

Public function Static

bool

 

IsNearlyEqual

(
    float A,
    float B,
    float ErrorTolerance
)

Checks if two floating point numbers are nearly equal.

Public function Static

bool

 

IsNearlyEqual

(
    double A,
    double B,
    double ErrorTolerance
)

Public function Static

bool

 

IsNearlyEqualByULP

(
    float A,
    float B,
    int32 MaxUlps
)

Check if two floating point numbers are nearly equal to within specific number of units of last place (ULP).

Public function Static

bool

 

IsNearlyEqualByULP

(
    double A,
    double B,
    int32 MaxUlps
)

Check if two floating point numbers are nearly equal to within specific number of units of last place (ULP).

Public function Static

bool

 

IsNearlyZero

(
    float Value,
    float ErrorTolerance
)

Checks if a floating point number is nearly zero.

Public function Static

bool

 

IsNearlyZero

(
    double Value,
    double ErrorTolerance
)

Checks if a floating point number is nearly zero.

Public function Static

constexpr bo...

 

IsPowerOfTwo

(
    T Value
)

Checks whether a number is a power of two.

Public function Static

constexpr bo...

 

IsWithin

(
    const T& TestValue,
    const U& MinValue,
    const U& MaxValue
)

Checks if value is within a range, exclusive on MaxValue)

Public function Static

constexpr bo...

 

IsWithinInclusive

(
    const T& TestValue,
    const U& MinValue,
    const U& MaxValue
)

Checks if value is within a range, inclusive on MaxValue)

Public function Static

constexpr in...

 

LeastCommonMultiplier

(
    int32 a,
    int32 b
)

LCM = a/gcd * b a and b are the number we want to find the lcm

Public function Static

constexpr T

 

Lerp

(
    const T& A,
    const T& B,
    const U& Alpha
)

Performs a linear interpolation between two values, Alpha ranges from 0-1

Public function Static

auto

 

Lerp

(
    const T1& A,
    const T2& B,
    const T3& Alpha
)

Allow passing of differing A/B types.

Public function Static

T

 

Lerp

(
    const T& A,
    const T& B,
    const U& Alpha
)

Custom lerps defined for those classes not suited to the default implemenation.

Public function Static

UE::Math::TR...

 

LerpRange

(
    const UE::Math::TRotator< T >& A,
    const UE::Math::TRotator< T >& B,
    U Alpha
)

Rotator specific interpolation Similar to Lerp, but does not take the shortest path.

Public function Static

constexpr T

 

LerpStable

(
    const T& A,
    const T& B,
    float Alpha
)

Performs a linear interpolation between two values, Alpha ranges from 0-1.

Public function Static

auto

 

LerpStable

(
    const T1& A,
    const T2& B,
    const T3& Alpha
)

Allow passing of differing A/B types.

Public function Static

constexpr T

 

LerpStable

(
    const T& A,
    const T& B,
    double Alpha
)

Performs a linear interpolation between two values, Alpha ranges from 0-1.

Public function Static

bool

 

LineBoxIntersection

(
    const UE::Math::TBox< FReal >& Box,
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TVector< FReal >& ...
)

Determines whether a line intersects a box.

Public function Static

bool

 

LineBoxIntersection

(
    const UE::Math::TBox< FReal >& Box,
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TVector< FReal >& ...
)

Determines whether a line intersects a box.

Public function Static

bool

 

LineExtentBoxIntersection

(
    const FBox& inBox,
    const FVector& Start,
    const FVector& End,
    const FVector& Extent,
    FVector& HitLocation,
    FVector& HitNormal,
    float& HitTime
)

Swept-Box vs Box test

Public function

UE::Math::TV...

 

LinePlaneIntersection

(
    const UE::Math::TVector< T >& Poin...,
    const UE::Math::TVector< T >& Poin...,
    const UE::Math::TVector< T >& Plan...,
    const UE::Math::TVector< T >& Plan...
)

FMath inline functions

Public function

UE::Math::TV...

 

LinePlaneIntersection

(
    const UE::Math::TVector< T >& Poin...,
    const UE::Math::TVector< T >& Poin...,
    const UE::Math::TPlane< T >& Plane
)

Public function Static

UE::Math::TV...

 

LinePlaneIntersection

(
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TVector< FReal >& ...
)

Find the intersection of a line and an offset plane.

Public function Static

UE::Math::TV...

 

LinePlaneIntersection

(
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TPlane< FReal >& P...
)

Find the intersection of a line and a plane.

Public function Static

bool

 

LineSphereIntersection

(
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TVector< FReal >& ...,
    FReal Length,
    const UE::Math::TVector< FReal >& ...,
    FReal Radius
)

Determines whether a line intersects a sphere.

Public function

bool

 

LineSphereIntersection

(
    const UE::Math::TVector< T >& Star...,
    const UE::Math::TVector< T >& Dir,
    T Length,
    const UE::Math::TVector< T >& Orig...,
    T Radius
)

Public function Static

float

 

Log2

(
    float Value
)

Computes the base 2 logarithm of the specified value

Public function Static

double

 

Log2

(
    double Value
)

Computes the base 2 logarithm of the specified value

Public function Static

float

 

MakePulsatingValue

(
    const double InCurrentTime,
    const float InPulsesPerSecond,
    const float InPhase
)

Simple function to create a pulsating scalar value

Public function Static

constexpr T

 

Max3

(
    const T A,
    const T B,
    const T C
)

Returns highest of 3 values

Public function Static

bool

 

MemoryTest

(
    void* BaseAddress,
    uint32 NumBytes
)

Tests a memory region to see that it's working properly.

Public function Static

constexpr T

 

Min3

(
    const T A,
    const T B,
    const T C
)

Returns lowest of 3 values

Public function

 

MIX_TYPES_2_ARGS

(
    GridSnap
)

Public function

 

MIX_TYPES_3_ARGS

(
    Clamp
)

Public function Static

float

 

PerlinNoise1D

(
    float Value
)

Generates a 1D Perlin noise from the given value.

Public function Static

float

 

PerlinNoise2D

(
    const FVector2D& Location
)

Generates a 1D Perlin noise sample at the given location.

Public function Static

float

 

PerlinNoise3D

(
    const FVector& Location
)

Generates a 3D Perlin noise sample at the given location.

Public function Static

bool

 

PlaneAABBIntersection

(
    const FPlane& P,
    const FBox& AABB
)

Determine if a plane and an AABB intersect

Public function Static

int32

 

PlaneAABBRelativePosition

(
    const FPlane& P,
    const FBox& AABB
)

Determine the position of an AABB relative to a plane: completely above (in the direction of the normal of the plane), completely below or intersects it

Public function Static

bool

 

PointBoxIntersection

(
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TBox< FReal >& Box
)

Determines whether a point is inside a box.

Public function Static

float

 

PointDistToLine

(
    const FVector& Point,
    const FVector& Direction,
    const FVector& Origin,
    FVector& OutClosestPoint
)

Calculates the distance of a given Point in world space to a given line, defined by the vector couple (Origin, Direction).

Public function Static

float

 

PointDistToLine

(
    const FVector& Point,
    const FVector& Direction,
    const FVector& Origin
)

Calculates the distance of a given Point in world space to a given line, defined by the vector couple (Origin, Direction).

Public function Static

float

 

PointDistToSegment

(
    const FVector& Point,
    const FVector& StartPoint,
    const FVector& EndPoint
)

Returns distance from a point to the closest point on a segment.

Public function Static

float

 

PointDistToSegmentSquared

(
    const FVector& Point,
    const FVector& StartPoint,
    const FVector& EndPoint
)

Returns square of the distance from a point to the closest point on a segment.

Public function Static

bool

 

PointsAreCoplanar

(
    const TArray< FVector >& Points,
    const float Tolerance
)

Determines whether a given set of points are coplanar, with a tolerance.

Public function Static

void

 

PolarToCartesian

(
    const T Rad,
    const T Ang,
    T& OutX,
    T& OutY
)

Converts given Polar coordinate pair to Cartesian coordinate system.

Public function Static

void

 

PolarToCartesian

(
    const UE::Math::TVector2< T > InPol...,
    UE::Math::TVector2< T >& OutCart
)

Converts given Polar coordinate pair to Cartesian coordinate system.

Public function Static

UE::Math::TQ...

 

QInterpConstantTo

(
    const UE::Math::TQuat< T >& Curren...,
    const UE::Math::TQuat< T >& Target,
    float DeltaTime,
    float InterpSpeed
)

Interpolate quaternion from Current to Target with constant step (in radians)

Public function Static

UE::Math::TQ...

 

QInterpTo

(
    const UE::Math::TQuat< T >& Curren...,
    const UE::Math::TQuat< T >& Target,
    float DeltaTime,
    float InterpSpeed
)

Interpolate quaternion from Current to Target.

Public function Static

uint8

 

Quantize8SignedByte

(
    float x
)

Public function Static

uint8

 

Quantize8UnsignedByte

(
    float x
)

Public function Static

double

 

RadiansToDegrees

(
    double const& RadVal
)

Public function Static

constexpr au...

 

RadiansToDegrees

(
    T const& RadVal
)

Converts radians to degrees.

Public function Static

float

 

RadiansToDegrees

(
    float const& RadVal
)

Public function Static

bool

 

RandBool()

Util to generate a random boolean.

Public function Static

int32

 

RandHelper

(
    int32 A
)

Helper function for rand implementations. Returns a random number in [0..A)

Public function Static

int64

 

RandHelper64

(
    int64 A
)

Public function Static

FVector

 

RandPointInBox

(
    const FBox& Box
)

Returns a random point within the passed in bounding box

Public function Static

FVector2D

 

RandPointInCircle

(
    float CircleRadius
)

Returns a random point, uniformly distributed, within the specified radius

Public function Static

double

 

RandRange

(
    double InMin,
    double InMax
)

Public function Static

float

 

RandRange

(
    float InMin,
    float InMax
)

Util to generate a random number in a range.

Public function Static

int64

 

RandRange

(
    int64 Min,
    int64 Max
)

Public function Static

int32

 

RandRange

(
    int32 Min,
    int32 Max
)

Helper function for rand implementations. Returns a random number >= Min and <= Max

Public function

UE::Math::TV...

 

RayPlaneIntersection

(
    const UE::Math::TVector< T >& RayO...,
    const UE::Math::TVector< T >& RayD...,
    const UE::Math::TPlane< T >& Plane
)

FMath inline functions

Public function Static

UE::Math::TV...

 

RayPlaneIntersection

(
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TVector< FReal >& ...,
    const UE::Math::TPlane< FReal >& P...
)

Find the intersection of a ray and a plane.

Public function

 

RESOLVE_FLOAT_AMBIGUITY_2_ARGS

(
    FRandRange
)

Public function

 

RESOLVE_FLOAT_PREDICATE_AMBIGUITY

(
    IsNearlyZero
)

Public function

 

RESOLVE_FLOAT_PREDICATE_AMBIGUITY_2_ARGS

(
    IsNearlyZero
)

Public function

 

RESOLVE_FLOAT_PREDICATE_AMBIGUITY_2_ARGS

(
    IsNearlyEqual
)

Public function

 

RESOLVE_FLOAT_PREDICATE_AMBIGUITY_3_ARGS

(
    IsNearlyEqual
)

Public function Static

FRotator

 

RInterpConstantTo

(
    const FRotator& Current,
    const FRotator& Target,
    float DeltaTime,
    float InterpSpeed
)

Interpolate rotator from Current to Target with constant step

Public function Static

FRotator

 

RInterpTo

(
    const FRotator& Current,
    const FRotator& Target,
    float DeltaTime,
    float InterpSpeed
)

Interpolate rotator from Current to Target.

Public function Static

float

 

RoundFromZero

(
    float F
)

Converts a floating point number to an integer which is further from zero, "larger" in absolute value: 0.1 becomes 1, -0.1 becomes -1

Public function Static

double

 

RoundFromZero

(
    double F
)

Public function Static

float

 

RoundHalfFromZero

(
    float F
)

Converts a floating point number to the nearest integer, equidistant ties go to the value which is further from zero: -0.5 becomes -1.0, 0.5 becomes 1.0

Public function Static

double

 

RoundHalfFromZero

(
    double F
)

Converts a floating point number to the nearest integer, equidistant ties go to the value which is further from zero: -0.5 becomes -1.0, 0.5 becomes 1.0

Public function Static

float

 

RoundHalfToEven

(
    float F
)

Converts a floating point number to the nearest integer, equidistant ties go to the value which is closest to an even value: 1.5 becomes 2, 0.5 becomes 0

Public function Static

double

 

RoundHalfToEven

(
    double F
)

Converts a floating point number to the nearest integer, equidistant ties go to the value which is closest to an even value: 1.5 becomes 2, 0.5 becomes 0

Public function Static

float

 

RoundHalfToZero

(
    float F
)

Converts a floating point number to the nearest integer, equidistant ties go to the value which is closer to zero: -0.5 becomes 0, 0.5 becomes 0

Public function Static

double

 

RoundHalfToZero

(
    double F
)

Converts a floating point number to the nearest integer, equidistant ties go to the value which is closer to zero: -0.5 becomes 0, 0.5 becomes 0

Public function Static

float

 

RoundToNegativeInfinity

(
    float F
)

Converts a floating point number to an integer which is more negative: 0.1 becomes 0, -0.1 becomes -1

Public function Static

double

 

RoundToNegativeInfinity

(
    double F
)

Public function Static

double

 

RoundToPositiveInfinity

(
    double F
)

Public function Static

float

 

RoundToPositiveInfinity

(
    float F
)

Converts a floating point number to an integer which is more positive: 0.1 becomes 1, -0.1 becomes 0

Public function Static

float

 

RoundToZero

(
    float F
)

Converts a floating point number to an integer which is closer to zero, "smaller" in absolute value: 0.1 becomes 0, -0.1 becomes 0

Public function Static

double

 

RoundToZero

(
    double F
)

Public function Static

void

 

SegmentDistToSegment

(
    FVector A1,
    FVector B1,
    FVector A2,
    FVector B2,
    FVector& OutP1,
    FVector& OutP2
)

Find closest points between 2 segments.

Public function Static

void

 

SegmentDistToSegmentSafe

(
    FVector A1,
    FVector B1,
    FVector A2,
    FVector B2,
    FVector& OutP1,
    FVector& OutP2
)

Find closest points between 2 segments.

Public function Static

bool

 

SegmentIntersection2D

(
    const FVector& SegmentStartA,
    const FVector& SegmentEndA,
    const FVector& SegmentStartB,
    const FVector& SegmentEndB,
    FVector& out_IntersectionPoint
)

Returns true if there is an intersection between the segment specified by SegmentStartA and SegmentEndA, and the segment specified by SegmentStartB and SegmentEndB, in 2D space.

Public function Static

bool

 

SegmentPlaneIntersection

(
    const FVector& StartPoint,
    const FVector& EndPoint,
    const FPlane& Plane,
    FVector& out_IntersectionPoint
)

Returns true if there is an intersection between the segment specified by StartPoint and Endpoint, and the plane on which polygon Plane lies.

Public function Static

bool

 

SegmentTriangleIntersection

(
    const FVector& StartPoint,
    const FVector& EndPoint,
    const FVector& A,
    const FVector& B,
    const FVector& C,
    FVector& OutIntersectPoint,
    FVector& OutTriangleNormal
)

Returns true if there is an intersection between the segment specified by StartPoint and Endpoint, and the Triangle defined by A, B and C.

Public function Static

constexpr vo...

 

SetBoolInBitField

(
    uint8* Ptr,
    uint32 Index,
    bool bSet
)

Set a bit in memory created from bitflags (uint32 Value:1), used for EngineShowFlags, TestBitFieldFunctions() tests the implementation

Public function Static

constexpr vo...

 

SinCos

(
    typename TDecay< T >::Type* Sc...,
    typename TDecay< T >::Type* Sc...,
    T Value
)

Computes the sine and cosine of a scalar value.

Public function Static

void

 

SinCos

(
    T* ScalarSin,
    T* ScalarCos,
    U Value
)

Public function Static

void

 

SinCos

(
    double* ScalarSin,
    double* ScalarCos,
    double Value
)

Public function Static

constexpr T

 

SmoothStep

(
    T A,
    T B,
    T X
)

Returns a smooth Hermite interpolation between 0 and 1 for the value X (where X ranges between A and B) Clamped to 0 for X <= A and 1 for X >= B.

Public function Static

bool

 

SphereAABBIntersection

(
    const UE::Math::TSphere< FReal >& ...,
    const UE::Math::TBox< FReal >& AAB...
)

Converts a sphere into a point plus radius squared for the test above

Public function Static

bool

 

SphereAABBIntersection

(
    const UE::Math::TVector< FReal >& ...,
    const FReal RadiusSquared,
    const UE::Math::TBox< FReal >& AAB...
)

Performs a sphere vs box intersection test using Arvo's algorithm:

Public function Static

bool

 

SphereConeIntersection

(
    const FVector& SphereCenter,
    float SphereRadius,
    const FVector& ConeAxis,
    float ConeAngleSin,
    float ConeAngleCos
)

Assumes the cone tip is at 0,0,0 (means the SphereCenter is relative to the cone tip)

Public function Static

void

 

SphereDistToLine

(
    FVector SphereOrigin,
    float SphereRadius,
    FVector LineOrigin,
    FVector LineDir,
    FVector& OutClosestPoint
)

Find closest point on a Sphere to a Line.

Public function Static

void

 

SpringDamper

(
    T& InOutValue,
    T& InOutValueRate,
    const T& InTargetValue,
    const T& InTargetValueRate,
    const float InDeltaTime,
    const float InUndampedFrequency,
    const float InDampingRatio
)

Smooths a value using a spring damper towards a target.

Public function Static

void

 

SpringDamperSmoothing

(
    T& InOutValue,
    T& InOutValueRate,
    const T& InTargetValue,
    const T& InTargetValueRate,
    const float InDeltaTime,
    const float InSmoothingTime,
    const float InDampingRatio
)

Smooths a value using a spring damper towards a target.

Public function Static

constexpr T

 

Square

(
    const T A
)

Multiples value by itself

Public function Static

float

 

TruncateToHalfIfClose

(
    float F,
    float Tolerance
)

Truncates a floating point number to half if closer than the given tolerance.

Public function Static

double

 

TruncateToHalfIfClose

(
    double F,
    double Tolerance
)

Truncates a floating point number to half if closer than the given tolerance.

Public function Static

constexpr T

 

UnwindDegrees

(
    T A
)

Utility to ensure angle is between +/- 180 degrees by unwinding.

Public function Static

constexpr T

 

UnwindRadians

(
    T A
)

Given a heading which may be outside the +/- PI range, 'unwind' it back into that range.

Public function Static

FVector2D

 

Vector2DInterpConstantTo

(
    const FVector2D& Current,
    const FVector2D& Target,
    float DeltaTime,
    float InterpSpeed
)

Interpolate vector2D from Current to Target with constant step

Public function Static

FVector2D

 

Vector2DInterpTo

(
    const FVector2D& Current,
    const FVector2D& Target,
    float DeltaTime,
    float InterpSpeed
)

Interpolate vector2D from Current to Target.

Public function Static

FVector

 

VInterpConstantTo

(
    const FVector& Current,
    const FVector& Target,
    float DeltaTime,
    float InterpSpeed
)

Interpolate vector from Current to Target with constant step

Public function Static

FVector

 

VInterpNormalRotationTo

(
    const FVector& Current,
    const FVector& Target,
    float DeltaTime,
    float RotationSpeedDegrees
)

Interpolate a normal vector Current to Target, by interpolating the angle between those vectors with constant step.

Public function Static

FVector

 

VInterpTo

(
    const FVector& Current,
    const FVector& Target,
    float DeltaTime,
    float InterpSpeed
)

Interpolate vector from Current to Target.

Public function Static

FVector

 

VRand()

Return a uniformly distributed random unit length vector = point on the unit sphere surface.

Public function Static

FVector

 

VRandCone

(
    FVector const& Dir,
    float ConeHalfAngleRad
)

Returns a random unit vector, uniformly distributed, within the specified cone ConeHalfAngleRad is the half-angle of cone, in radians.

Public function Static

FVector

 

VRandCone

(
    FVector const& Dir,
    float HorizontalConeHalfAngleRad,
    float VerticalConeHalfAngleRad
)

This is a version of VRandCone that handles "squished" cones, i.e. with different angle limits in the Y and Z axes.

Public function Static

T

 

WeightedMovingAverage

(
    T CurrentSample,
    T PreviousSample,
    T Weight
)

Calculates the new value in a weighted moving average series using the previous value and the weight

Public function Static

void

 

WindRelativeAnglesDegrees

(
    float InAngle0,
    float& InOutAngle1
)

Given two angles in degrees, 'wind' the rotation in Angle1 so that it avoids >180 degree flips.

Public function Static

void

 

WindRelativeAnglesDegrees

(
    double InAngle0,
    double& InOutAngle1
)

Given two angles in degrees, 'wind' the rotation in Angle1 so that it avoids >180 degree flips.

Public function Static

constexpr T

 

Wrap

(
    const T X,
    const T Min,
    const T Max
)

Wraps X to be between Min and Max, inclusive.

Constants

Name

Description

BitFlag

32 bit values where BitFlag[x] == (1<

Deprecated Functions

Name Description

Public function Static

void

 

CartesianToPolar

(
    const T1 X,
    const T2 Y,
    T3& OutRad,
    T3& OutAng
)

Arguments cause function resolution ambiguity.

Public function Static

float

 

DynamicWeightedMovingAverage

(
    T1&& CurrentSample,
    T2&& PreviousSample,
    T3&& MaxDistance,
    T4&& MinWeight,
    T5&& MaxWeight
)

Arguments cause function resolution ambiguity.

Public function Static

constexpr fl...

 

FindDeltaAngle

(
    float A1,
    float A2
)

Please use FindDeltaAngleRadians(float A1, float A2) instead of FindDeltaAngle(float A1, float A2).

Public function Static

float

 

Log2

(
    T&& Value
)

Arguments cause function resolution ambiguity.

Public function Static

void

 

PolarToCartesian

(
    const T1 Rad,
    const T2 Ang,
    T3& OutX,
    T3& OutY
)

Arguments cause function resolution ambiguity.

Public function Static

float

 

SmoothStep

(
    T1&& A,
    T2&& B,
    T3&& C
)

Arguments cause function resolution ambiguity.

Public function Static

float

 

WeightedMovingAverage

(
    T1&& CurrentSample,
    T2&& PreviousSample,
    T3&& Weight
)

Arguments cause function resolution ambiguity.