Language
Edit

MathUtilities Class

Definition

Useful utilities for manipulating datatype sizes, conversion factors, quaternions, matrices, and other mathematical tasks.

public static class MathUtilities
type MathUtilities = class
Public Class MathUtilities
Inheritance
MathUtilities

Fields

Name Description
Megabyte

The total number of bytes in a megabyte.

Methods

Name Description
Add(Matrix4x4, Matrix4x4)

Element-wise addition of two Matrix4x4s - extension method

BytesToFloat(Byte, Byte)

Converts two bytes to one float in the range -1 to 1.

BytesToInt(Byte[], Int32)

Converts an array of four bytes to an integer.

BytesToMegabytes(UInt64)

Converts bytes to megabytes.

BytesToShort(Byte[], Int32)

Converts an array of two bytes to a short integer.

CLampLerp(Single, Single, Single, Single)

Clamps via a lerp for a "soft" clamp effect

ClosestPointOnLineSegmentToPoint(Vector3, Vector3, Vector3)

Get the closest point from a given point and a line segment defined by two other points.

ClosestPointOnLineToPoint(Vector3, Vector3, Vector3)

Get the closest point from a given point and an infinite line defined by two other points.

DegreesToRadians(Double)

Convert degrees to radians.

DistanceOfPointToLine(Ray, Vector3)

find unsigned distance of 3D point to an infinite line

DistanceOfPointToLine(Vector3, Vector3, Vector3)

Get the distance between a given point and an infinite line defined by two other points.

DistanceOfPointToLineSegment(Vector3, Vector3, Vector3)

Get the distance between a given point and a line segment defined by two other points.

GetAngleBetween(Vector2, Vector2)

Calculates the angle (at pointA) between two, two-dimensional points.

GetDirection(Quaternion)

Calculates the direction vector from a rotation.

InRange(Vector2, Vector2, Vector2)

Tests component-wise if a Vector2 is in a given range

InRange(Vector3, Vector3, Vector3)

Tests component-wise if a Vector3 is in a given range

IsInFOV(Vector3, Transform, Single, Single, Single, Single)

Returns if a point lies within a frame of reference view as defined by arguments

IsInFOVCone(Transform, Vector3, Single, Single, Single)

Returns true if a point lies inside the cone described with given parameters, false otherwise. The cone is inscribed to a radius equal to the vertical height of the provided FOV. The test also ensures the distance from the point to the cone lies within the given range.

MegabytesToBytes(Single)

Converts megabytes to bytes.

NearestPointToLines(Ray, Ray)

Find 3D point that minimizes distance to 2 lines, midpoint of the shortest perpendicular line segment between them

NearestPointToLinesLeastSquares(IEnumerable<Ray>)

Find 3D point that minimizes distance to a set of 2 or more lines

NearestPointToLinesRANSAC(List<Ray>, Int32, Single, Int32)

Find 3D point that minimizes distance to a set of 2 or more lines, ignoring outliers

QuaternionFromMatrix(Matrix4x4)

Creates a quaternion containing the rotation from the input matrix.

RadiansToDegrees(Single)

Convert radians to degrees.

ScaleFromAngularSizeAndDistance(Single, Single)

Retrieve angular measurement describing how large a sphere or circle appears from a given point of view. Takes an angle (at given point of view) and a distance and returns the actual diameter of the object.

Subtract(Matrix4x4, Matrix4x4)

Element-wise subtraction of two Matrix4x4s - extension method

TestPlanesAABB(Plane[], Int32, Bounds, Boolean)

Test if the given planes are inside the given bounds.

ToTranslationRotation(Matrix4x4, Vector3, Quaternion)

Extract the translation and rotation components of a Unity matrix

TransformDirectionFromTo(Transform, Transform, Vector3)

Takes a direction in the coordinate space specified by the "from" transform and transforms it to be the correct direction in the coordinate space specified by the "to" transform applies rotation only, no translation or scale

TransformPointFromTo(Transform, Transform, Vector3)

Takes a point in the coordinate space specified by the "from" transform and transforms it to be the correct point in the coordinate space specified by the "to" transform applies rotation, scale and translation.

TransformRayFromTo(Transform, Transform, Ray)

Takes a ray in the coordinate space specified by the "from" transform and transforms it to be the correct ray in the coordinate space specified by the "to" transform

TransformVectorFromTo(Transform, Transform, Vector3)

Takes a vector in the coordinate space specified by the "from" transform and transforms it to be the correct direction in the coordinate space specified by the "to" transform applies rotation and scale, no translation

XYProject(Vector3)

Project vector onto the XY plane.

XZProject(Vector3)

Project vector onto XZ plane

YZProject(Vector3)

Project vector onto YZ plane

Applies to