Class Math
Helper functions.
Inherited Members
Namespace: Unity.Physics
Assembly: Unity.Physics.dll
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, int)
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. |
int | twistAxisIndex | Zero-based index of the twist axis. |
Returns
Type | Description |
---|---|
float | The calculated twist angle. |
ClampToMaxLength(float, ref float3)
Clamps the vector to to maximum length.
Declaration
public static void ClampToMaxLength(float maxLength, ref float3 vector)
Parameters
Type | Name | Description |
---|---|---|
float | 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(AffineTransform)
Obtain 3-dimensional scale vector of the provided affine transformation, 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 AffineTransform matrix)
Parameters
Type | Name | Description |
---|---|---|
AffineTransform | matrix | The affine transformation matrix. |
Returns
Type | Description |
---|---|
float3 | The three scale components of the provided affine transformation. |
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 | The three scale components of the provided transformation matrix. |
HasNonIdentityScale(float4x4, float)
Checks if the matrix has non-identity scale.
Declaration
public static bool HasNonIdentityScale(this float4x4 m, float eps = 1E-05)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | m | The matrix. |
float | eps | Epsilon value used in the non-identity scale determination. |
Returns
Type | Description |
---|---|
bool | True if the matrix has non-identity scale. |
HasNonUniformScale(float4x4, float)
Checks if the matrix has non-uniform scale.
Declaration
public static bool HasNonUniformScale(this float4x4 m, float eps = 1E-05)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | m | The matrix. |
float | eps | Epsilon value used in the non-uniform scale determination. |
Returns
Type | Description |
---|---|
bool | True if the matrix has non-uniform scale. |
HasShear(float4x4)
Checks if the matrix has shear.
Declaration
public static bool HasShear(this float4x4 m)
Parameters
Type | Name | Description |
---|---|---|
float4x4 | m | The matrix. |
Returns
Type | Description |
---|---|
bool | True if the matrix has shear. |
Inverse(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(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 |
---|---|
bool | True if normalized, false if not. |
Mul(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(MTransform, 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(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(ScaledMTransform, 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 |
---|---|
float | Length of v. |