Class MathUtilities
Math Utilities class.
Inherited Members
Namespace: Microsoft.MixedReality.Toolkit.Utilities
Assembly: cs.temp.dll.dll
Syntax
public static class MathUtilities
Methods
Add(Matrix4x4, Matrix4x4)
Element-wise addition of two Matrix4x4s - extension method
Declaration
public static Matrix4x4 Add(Matrix4x4 a, Matrix4x4 b)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4x4 | a | matrix |
| Matrix4x4 | b | matrix |
Returns
| Type | Description |
|---|---|
| Matrix4x4 | element-wise (a+b) |
ClosestPointOnLineSegmentToPoint(Vector3, Vector3, Vector3)
Declaration
public static Vector3 ClosestPointOnLineSegmentToPoint(Vector3 point, Vector3 lineStart, Vector3 lineEnd)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | point | |
| Vector3 | lineStart | |
| Vector3 | lineEnd |
Returns
| Type | Description |
|---|---|
| Vector3 |
ClosestPointOnLineToPoint(Vector3, Vector3, Vector3)
Declaration
public static Vector3 ClosestPointOnLineToPoint(Vector3 point, Vector3 linePointA, Vector3 linePointB)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | point | |
| Vector3 | linePointA | |
| Vector3 | linePointB |
Returns
| Type | Description |
|---|---|
| Vector3 |
DegreesToRadians(Double)
Convert degrees to radians.
Declaration
public static float DegreesToRadians(double degrees)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | degrees | Angle, in degrees. |
Returns
| Type | Description |
|---|---|
| Single | Angle, in radians. |
DistanceOfPointToLine(Ray, Vector3)
find unsigned distance of 3D point to an infinite line
Declaration
public static float DistanceOfPointToLine(Ray ray, Vector3 point)
Parameters
| Type | Name | Description |
|---|---|---|
| Ray | ray | ray that specifies an infinite line |
| Vector3 | point | 3D point |
Returns
| Type | Description |
|---|---|
| Single | unsigned perpendicular distance from point to line |
DistanceOfPointToLine(Vector3, Vector3, Vector3)
Returns the distance between a point and an infinite line defined by two points; linePointA and linePointB
Declaration
public static float DistanceOfPointToLine(Vector3 point, Vector3 linePointA, Vector3 linePointB)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | point | |
| Vector3 | linePointA | |
| Vector3 | linePointB |
Returns
| Type | Description |
|---|---|
| Single |
DistanceOfPointToLineSegment(Vector3, Vector3, Vector3)
Declaration
public static float DistanceOfPointToLineSegment(Vector3 point, Vector3 lineStart, Vector3 lineEnd)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | point | |
| Vector3 | lineStart | |
| Vector3 | lineEnd |
Returns
| Type | Description |
|---|---|
| Single |
GetAngleBetween(Vector2, Vector2)
Calculates the angle (at pointA) between two, two-dimensional points.
Declaration
public static float GetAngleBetween(Vector2 pointA, Vector2 pointB)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | pointA | The first point. |
| Vector2 | pointB | The second point. |
Returns
| Type | Description |
|---|---|
| Single | The angle between the two points. |
InRange(Vector2, Vector2, Vector2)
Tests component-wise if a Vector2 is in a given range
Declaration
public static bool InRange(Vector2 vec, Vector2 lower, Vector2 upper)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | vec | The vector to test |
| Vector2 | lower | The lower bounds |
| Vector2 | upper | The upper bounds |
Returns
| Type | Description |
|---|---|
| Boolean | true if in range, otherwise false |
InRange(Vector3, Vector3, Vector3)
Tests component-wise if a Vector3 is in a given range
Declaration
public static bool InRange(Vector3 vec, Vector3 lower, Vector3 upper)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | vec | The vector to test |
| Vector3 | lower | The lower bounds |
| Vector3 | upper | The upper bounds |
Returns
| Type | Description |
|---|---|
| Boolean | true if in range, otherwise false |
NearestPointToLines(Ray, Ray)
Find 3D point that minimizes distance to 2 lines, midpoint of the shortest perpendicular line segment between them
Declaration
public static Vector3 NearestPointToLines(Ray p, Ray q)
Parameters
| Type | Name | Description |
|---|---|---|
| Ray | p | ray that specifies a line |
| Ray | q | ray that specifies a line |
Returns
| Type | Description |
|---|---|
| Vector3 | point nearest to the lines |
NearestPointToLinesLeastSquares(IEnumerable<Ray>)
Find 3D point that minimizes distance to a set of 2 or more lines
Declaration
public static Vector3 NearestPointToLinesLeastSquares(IEnumerable<Ray> rays)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<Ray> | rays | each ray specifies an infinite line |
Returns
| Type | Description |
|---|---|
| Vector3 | point nearest to the set of lines |
NearestPointToLinesRANSAC(List<Ray>, Int32, Single, out Int32)
Find 3D point that minimizes distance to a set of 2 or more lines, ignoring outliers
Declaration
public static Vector3 NearestPointToLinesRANSAC(List<Ray> rays, int ransac_iterations, float ransac_threshold, out int numActualInliers)
Parameters
| Type | Name | Description |
|---|---|---|
| List<Ray> | rays | list of rays, each specifying a line, must have at least 1 |
| Int32 | ransac_iterations | number of iterations: log(1-p)/log(1-(1-E)^s) where p is probability of at least one sample containing s points is all inliers E is proportion of outliers (1-ransac_ratio) e.g. p=0.999, ransac_ratio=0.54, s=2 ==> log(0.001)/(log(1-0.54^2) = 20 |
| Single | ransac_threshold | minimum distance from point to line for a line to be considered an inlier |
| Int32 | numActualInliers | return number of inliers: lines that are within ransac_threshold of nearest point |
Returns
| Type | Description |
|---|---|
| Vector3 | point nearest to the set of lines, ignoring outliers |
QuaternionFromMatrix(Matrix4x4)
Creates a quaternion containing the rotation from the input matrix.
Declaration
public static Quaternion QuaternionFromMatrix(Matrix4x4 m)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4x4 | m | Input matrix to convert to quaternion |
Returns
| Type | Description |
|---|---|
| Quaternion |
RadiansToDegrees(Single)
Convert radians to degrees.
Declaration
public static float RadiansToDegrees(float radians)
Parameters
| Type | Name | Description |
|---|---|---|
| Single | radians | Angle, in radians. |
Returns
| Type | Description |
|---|---|
| Single | Angle, in degrees. |
Subtract(Matrix4x4, Matrix4x4)
Element-wise subtraction of two Matrix4x4s - extension method
Declaration
public static Matrix4x4 Subtract(Matrix4x4 a, Matrix4x4 b)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4x4 | a | matrix |
| Matrix4x4 | b | matrix |
Returns
| Type | Description |
|---|---|
| Matrix4x4 | element-wise (a-b) |
TestPlanesAABB(Plane[], Int32, Bounds, out Boolean)
Declaration
public static bool TestPlanesAABB(Plane[] planes, int planeMask, Bounds bounds, out bool entirelyInside)
Parameters
| Type | Name | Description |
|---|---|---|
| Plane[] | planes | |
| Int32 | planeMask | |
| Bounds | bounds | |
| Boolean | entirelyInside |
Returns
| Type | Description |
|---|---|
| Boolean |
ToTranslationRotation(Matrix4x4, out Vector3, out Quaternion)
Extract the translation and rotation components of a Unity matrix
Declaration
public static void ToTranslationRotation(Matrix4x4 unityMtx, out Vector3 translation, out Quaternion rotation)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix4x4 | unityMtx | |
| Vector3 | translation | |
| Quaternion | rotation |
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
Declaration
public static Vector3 TransformDirectionFromTo(Transform from, Transform to, Vector3 fromDirection)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | from | |
| Transform | to | |
| Vector3 | fromDirection |
Returns
| Type | Description |
|---|---|
| Vector3 | Direction to. |
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.
Declaration
public static Vector3 TransformPointFromTo(Transform from, Transform to, Vector3 fromPoint)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | from | |
| Transform | to | |
| Vector3 | fromPoint |
Returns
| Type | Description |
|---|---|
| Vector3 | Point to. |
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
Declaration
public static Ray TransformRayFromTo(Transform from, Transform to, Ray rayToConvert)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | from | |
| Transform | to | |
| Ray | rayToConvert |
Returns
| Type | Description |
|---|---|
| Ray |
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
Declaration
public static Vector3 TransformVectorFromTo(Transform from, Transform to, Vector3 vecInFrom)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | from | |
| Transform | to | |
| Vector3 | vecInFrom |
Returns
| Type | Description |
|---|---|
| Vector3 |
XYProject(Vector3)
Project vector onto XY plane
Declaration
public static Vector3 XYProject(Vector3 v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | v |
Returns
| Type | Description |
|---|---|
| Vector3 | result of projecting v onto XY plane |
XZProject(Vector3)
Project vector onto XZ plane
Declaration
public static Vector3 XZProject(Vector3 v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | v |
Returns
| Type | Description |
|---|---|
| Vector3 | result of projecting v onto XZ plane |
YZProject(Vector3)
Project vector onto YZ plane
Declaration
public static Vector3 YZProject(Vector3 v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | v |
Returns
| Type | Description |
|---|---|
| Vector3 | result of projecting v onto YZ plane |