Class Math
Helper functions.
Inherited Members
Namespace: Unity.Physics
Syntax
public static class Math
Methods
CalculatePerpendicularNormalized(float3, out float3, out float3)
Return two normals perpendicular to the input vector.
Declaration
public static void CalculatePerpendicularNormalized(float3 v, out float3 p, out float3 q)
Parameters
Type | Name | Description |
---|---|---|
float3 | v | Input vector. |
float3 | p | [out] Normal 1. |
float3 | q | [out] Normal 2. |
CalculateTwistAngle(quaternion, Int32)
Returns the twist angle of the swing-twist decomposition of q about i, j, or k corresponding to index = 0, 1, or 2 respectively. Full calculation for readability: float invLength = RSqrtSafe(dot * dot + w * w); float sinHalfAngle = dot * invLength; float cosHalfAngle = w * invLength; Observe: invLength cancels in the tan^-1(sin / cos) calc, so avoid unnecessary calculations.
Declaration
public static float CalculateTwistAngle(quaternion q, int twistAxisIndex)
Parameters
Type | Name | Description |
---|---|---|
quaternion | q | A quaternion to process. |
Int32 | twistAxisIndex | Zero-based index of the twist axis. |
Returns
Type | Description |
---|---|
Single | The calculated twist angle. |
ClampToMaxLength(Single, ref float3)
Clamps the vector to to maximum length.
Declaration
public static void ClampToMaxLength(float maxLength, ref float3 vector)
Parameters
Type | Name | Description |
---|---|---|
Single | maxLength | The maximum length. |
float3 | vector | [in,out] The vector to be clamped. |
DecomposeRigidBodyOrientation(in float4x4)
Physics internally represents all rigid bodies in world space. If a static body is in a hierarchy, its local-to-world matrix must be decomposed when building the physics world. This method returns a world-space orientation that would be decomposed for such a rigid body.
Declaration
public static quaternion DecomposeRigidBodyOrientation(in float4x4 localToWorld)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | localToWorld | The local to world. |
Returns
Type | Description |
---|---|
quaternion | A world-space orientation as used by physics. |
DecomposeRigidBodyTransform(in float4x4)
Physics internally represents all rigid bodies in world space. If a static body is in a hierarchy, its local-to-world matrix must be decomposed when building the physics world. This method returns a world-space RigidTransform that would be decomposed for such a rigid body.
Declaration
public static RigidTransform DecomposeRigidBodyTransform(in float4x4 localToWorld)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | localToWorld | The local to world. |
Returns
Type | Description |
---|---|
RigidTransform | A world-space RigidTransform as used by physics. |
DecomposeScale(float4x4)
Obtain 3-dimensional scale vector of the provided 4x4 transformation matrix, the components of which represent the lengths of the three orthonormal basis vectors forming the 3x3 rotational sub-matrix, respectively.
Declaration
public static float3 DecomposeScale(this float4x4 matrix)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | matrix | The 4x4 transformation matrix. |
Returns
Type | Description |
---|---|
float3 |
Inverse(Math.MTransform)
Inverses the given transform.
Declaration
public static Math.MTransform Inverse(Math.MTransform transform)
Parameters
Type | Name | Description |
---|---|---|
Math.MTransform | transform | A MTransform to process. |
Returns
Type | Description |
---|---|
Math.MTransform | An inverse of the provided transform. |
Inverse(Math.ScaledMTransform)
Inverses the given transform.
Declaration
public static Math.ScaledMTransform Inverse(Math.ScaledMTransform transform)
Parameters
Type | Name | Description |
---|---|---|
Math.ScaledMTransform | transform | A ScaledMTransform to process. |
Returns
Type | Description |
---|---|
Math.ScaledMTransform | A ScaledMTransform that is the inverse of the input. |
IsNormalized(float3)
Check if 'v' is normalized.
Declaration
public static bool IsNormalized(float3 v)
Parameters
Type | Name | Description |
---|---|---|
float3 | v | A float3 to check if normalized. |
Returns
Type | Description |
---|---|
Boolean | True if normalized, false if not. |
Mul(Math.MTransform, float3)
Multiplies the point by the transform.
Declaration
public static float3 Mul(Math.MTransform a, float3 x)
Parameters
Type | Name | Description |
---|---|---|
Math.MTransform | a | A MTransform to multiply with. |
float3 | x | A point to process. |
Returns
Type | Description |
---|---|
float3 | A transformed point. |
Mul(Math.MTransform, Math.MTransform)
Returns cFromA = cFromB * bFromA.
Declaration
public static Math.MTransform Mul(Math.MTransform cFromB, Math.MTransform bFromA)
Parameters
Type | Name | Description |
---|---|---|
Math.MTransform | cFromB | cFromB. |
Math.MTransform | bFromA | bFromA. |
Returns
Type | Description |
---|---|
Math.MTransform | A MTransform, cFromA. |
Mul(Math.ScaledMTransform, float3)
Multiplies the point by the transform.
Declaration
public static float3 Mul(Math.ScaledMTransform a, float3 x)
Parameters
Type | Name | Description |
---|---|---|
Math.ScaledMTransform | a | A ScaledMTransform to multiply with. |
float3 | x | A point to process. |
Returns
Type | Description |
---|---|
float3 | A transformed point. |
Mul(Math.ScaledMTransform, Math.ScaledMTransform)
Returns cFromA = cFromB * bFromA.
Declaration
public static Math.ScaledMTransform Mul(Math.ScaledMTransform cFromB, Math.ScaledMTransform bFromA)
Parameters
Type | Name | Description |
---|---|---|
Math.ScaledMTransform | cFromB | cFromB. |
Math.ScaledMTransform | bFromA | bFromA. |
Returns
Type | Description |
---|---|
Math.ScaledMTransform | A ScaledMTransform, cFromA. |
NormalizeWithLength(float3, out float3)
Normalize and return the lenght of a vector.
Declaration
public static float NormalizeWithLength(float3 v, out float3 n)
Parameters
Type | Name | Description |
---|---|---|
float3 | v | A float3 to normalize. |
float3 | n | [out] A normalized float3. |
Returns
Type | Description |
---|---|
Single | Length of v. |