Class MathUtils
Provides methods for miscellaneous mathematical operations.
Namespace: Mechatronics.SensorSDK
Syntax
public static class MathUtils
Fields
Epsilon
The default absolute tolerance for equality comparisons.
Declaration
public const float Epsilon = 1E-06F
Field Value
| Type | Description |
|---|---|
| Single | The default value is 1e-6. Read-only. |
EpsilonSquared
The default absolute tolerance for equality comparisons, squared.
Declaration
public const float EpsilonSquared = 1E-12F
Field Value
| Type | Description |
|---|---|
| Single | The default value is Epsilon squared. Read-only. |
Methods
AreApproxEqual(Single, Single, Single)
Checks if the magnitude of the difference between the given two floats is almost zero, using an absolute tolerance.
Declaration
public static bool AreApproxEqual(float a, float b, float toleranceSquared = 1E-12F)
Parameters
| Type | Name | Description |
|---|---|---|
| Single | a | The first value. |
| Single | b | The second value. |
| Single | toleranceSquared | The absolute tolerance, squared. The default value is EpsilonSquared. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the magnitude of the difference between the given two values is smaller than the tolerance. |
AreApproxEqual(Vector2, Vector2, Single)
Checks if the magnitude of the difference between the given two 2D vectors is almost zero, using an absolute tolerance.
Declaration
public static bool AreApproxEqual(Vector2 a, Vector2 b, float toleranceSquared = 1E-12F)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | a | The first value. |
| Vector2 | b | The second value. |
| Single | toleranceSquared | The absolute tolerance, squared. The default value is EpsilonSquared. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the magnitude of the difference between the given two values is smaller than the tolerance. |
AreApproxEqual(Vector3, Vector3, Single)
Checks if the magnitude of the difference between the given two 3D vectors is almost zero, using an absolute tolerance.
Declaration
public static bool AreApproxEqual(Vector3 a, Vector3 b, float toleranceSquared = 1E-12F)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | a | The first value. |
| Vector3 | b | The second value. |
| Single | toleranceSquared | The absolute tolerance, squared. The default value is EpsilonSquared. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the magnitude of the difference between the given two values is smaller than the tolerance. |
AreApproxEqual(Vector4, Vector4, Single)
Checks if the magnitude of the difference between the given two 4D vectors is almost zero, using an absolute tolerance.
Declaration
public static bool AreApproxEqual(Vector4 a, Vector4 b, float toleranceSquared = 1E-12F)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector4 | a | The first value. |
| Vector4 | b | The second value. |
| Single | toleranceSquared | The absolute tolerance, squared. The default value is EpsilonSquared. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the magnitude of the difference between the given two values is smaller than the tolerance. |
Cross(Vector2, Vector2)
Computes the cross product of two 2D vectors as v1.x * v2.y - v1.y * v2.x.
Declaration
public static float Cross(Vector2 v1, Vector2 v2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | v1 | First vector. |
| Vector2 | v2 | Second vector. |
Returns
| Type | Description |
|---|---|
| Single | The 2D cross product. |
Remarks
This is equivalent to promoting the operands to 3D vectors by setting their Z coordinates to 0,
computing their 3D cross product, then returning the Z coordinate of the result.
Equals |v1||v2|sin(theta). If v1 and v2 are unit vectors, returns the signed sine of their angle.
Returns a positive value if the smallest rotation bringing v1 to v2 is counter-clockwise.
IsApproxZero(Single, Single)
Checks if the given float is almost zero, using an absolute tolerance.
Declaration
public static bool IsApproxZero(float f, float toleranceSquared = 1E-12F)
Parameters
| Type | Name | Description |
|---|---|---|
| Single | f | The float to check. |
| Single | toleranceSquared | The absolute tolerance, squared. The default value is EpsilonSquared. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the magnitude of the given value is smaller than the tolerance. |
IsApproxZero(Vector2, Single)
Checks if the magnitude of the given 2D vector is almost zero, using an absolute tolerance.
Declaration
public static bool IsApproxZero(Vector2 v, float toleranceSquared = 1E-12F)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | v | The 2D vector to check. |
| Single | toleranceSquared | The absolute tolerance, squared. The default value is EpsilonSquared. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the magnitude of the given value is smaller than the tolerance. |
IsApproxZero(Vector3, Single)
Checks if the magnitude of the given 3D vector is almost zero, using an absolute tolerance.
Declaration
public static bool IsApproxZero(Vector3 v, float toleranceSquared = 1E-12F)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | v | The 3D vector to check. |
| Single | toleranceSquared | The absolute tolerance, squared. The default value is EpsilonSquared. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the magnitude of the given value is smaller than the tolerance. |
IsApproxZero(Vector4, Single)
Checks if the magnitude of the given 4D vector is almost zero, using an absolute tolerance.
Declaration
public static bool IsApproxZero(Vector4 v, float toleranceSquared = 1E-12F)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector4 | v | The 4D vector to check. |
| Single | toleranceSquared | The absolute tolerance, squared. The default value is EpsilonSquared. |
Returns
| Type | Description |
|---|---|
| Boolean | True if the magnitude of the given value is smaller than the tolerance. |
Square(Int32)
Computes the square of an integer.
Declaration
public static int Square(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | value | The value to square. |
Returns
| Type | Description |
|---|---|
| Int32 | The squared value. |
Square(Single)
Computes the square of a float.
Declaration
public static float Square(float value)
Parameters
| Type | Name | Description |
|---|---|---|
| Single | value | The value to square. |
Returns
| Type | Description |
|---|---|
| Single | The squared value. |
Swap<T>(ref T, ref T)
Swaps the values of the given arguments.
Declaration
public static void Swap<T>(ref T a, ref T b)
Parameters
| Type | Name | Description |
|---|---|---|
| T | a | First value. |
| T | b | Second value. |
Type Parameters
| Name | Description |
|---|---|
| T | Any type. Works both for value types and reference types. |
ToQuaternion(Vector4)
Converts a Vector4 into a Quaternion. Member-wise copy.
Declaration
public static Quaternion ToQuaternion(Vector4 v)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector4 | v | The Vector4 to convert. |
Returns
| Type | Description |
|---|---|
| Quaternion | The given value converted to a Quaternion. |
ToVector4(Quaternion)
Converts a Quaternion into a Vector4. Member-wise copy.
Declaration
public static Vector4 ToVector4(Quaternion q)
Parameters
| Type | Name | Description |
|---|---|---|
| Quaternion | q | The Quaternion to convert. |
Returns
| Type | Description |
|---|---|
| Vector4 | The given value converted to a Vector4. |