Class UnityVectorExtensions
Extensions to the Vector3 class, used by Cinemachine
Namespace: Cinemachine.Utility
Syntax
public static class UnityVectorExtensions
Fields
Epsilon
A useful Epsilon
Declaration
public const float Epsilon = 0.0001F
Field Value
Type | Description |
---|---|
Single |
Methods
Abs(Vector3)
Component-wise absolute value
Declaration
public static Vector3 Abs(this Vector3 v)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | v |
Returns
Type | Description |
---|---|
Vector3 |
AlmostZero(Vector3)
Is the vector within Epsilon of zero length?
Declaration
public static bool AlmostZero(this Vector3 v)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | v |
Returns
Type | Description |
---|---|
Boolean | True if the square magnitude of the vector is within Epsilon of zero |
Angle(Vector3, Vector3)
Much more stable for small angles than Unity's native implementation
Declaration
public static float Angle(Vector3 v1, Vector3 v2)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | v1 | |
Vector3 | v2 |
Returns
Type | Description |
---|---|
Single |
ClosestPointOnSegment(Vector2, Vector2, Vector2)
Get the closest point on a line segment.
Declaration
public static float ClosestPointOnSegment(this Vector2 p, Vector2 s0, Vector2 s1)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | p | A point in space |
Vector2 | s0 | Start of line segment |
Vector2 | s1 | End of line segment |
Returns
Type | Description |
---|---|
Single | The interpolation parameter representing the point on the segment, with 0==s0, and 1==s1 |
ClosestPointOnSegment(Vector3, Vector3, Vector3)
Get the closest point on a line segment.
Declaration
public static float ClosestPointOnSegment(this Vector3 p, Vector3 s0, Vector3 s1)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | p | A point in space |
Vector3 | s0 | Start of line segment |
Vector3 | s1 | End of line segment |
Returns
Type | Description |
---|---|
Single | The interpolation parameter representing the point on the segment, with 0==s0, and 1==s1 |
ProjectOntoPlane(Vector3, Vector3)
Returns a non-normalized projection of the supplied vector onto a plane as described by its normal
Declaration
public static Vector3 ProjectOntoPlane(this Vector3 vector, Vector3 planeNormal)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | |
Vector3 | planeNormal | The normal that defines the plane. Must have a length of 1. |
Returns
Type | Description |
---|---|
Vector3 | The component of the vector that lies in the plane |
SignedAngle(Vector3, Vector3, Vector3)
Much more stable for small angles than Unity's native implementation
Declaration
public static float SignedAngle(Vector3 v1, Vector3 v2, Vector3 up)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | v1 | |
Vector3 | v2 | |
Vector3 | up |
Returns
Type | Description |
---|---|
Single |
SlerpWithReferenceUp(Vector3, Vector3, Single, Vector3)
This is a slerp that mimics a camera operator's movement in that it chooses a path that avoids the lower hemisphere, as defined by the up param
Declaration
public static Vector3 SlerpWithReferenceUp(Vector3 vA, Vector3 vB, float t, Vector3 up)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vA | First direction |
Vector3 | vB | Second direction |
Single | t | Interpolation amoun t |
Vector3 | up | Defines the up direction |
Returns
Type | Description |
---|---|
Vector3 |