Class UnityVectorExtensions | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    Class UnityVectorExtensions

    Extensions to the Vector3 class, used by Cinemachine

    Inheritance
    System.Object
    UnityVectorExtensions
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ToString()
    System.Object.ReferenceEquals(System.Object, System.Object)
    Namespace: Cinemachine.Utility
    Syntax
    public static class UnityVectorExtensions

    Fields

    Epsilon

    A useful Epsilon

    Declaration
    public const float Epsilon = 0.0001F
    Field Value
    Type Description
    System.Single

    Methods

    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
    System.Boolean

    True if the square magnitude of the vector is within Epsilon of zero

    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
    System.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
    System.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. Cannot be zero-length.

    Returns
    Type Description
    Vector3

    The component of the vector that lies in the plane

    SignedAngle(Vector3, Vector3, Vector3)

    Get a signed angle between two vectors

    Declaration
    public static float SignedAngle(Vector3 from, Vector3 to, Vector3 refNormal)
    Parameters
    Type Name Description
    Vector3 from

    Start direction

    Vector3 to

    End direction

    Vector3 refNormal

    This is needed in order to determine the sign. For example, if from an to lie on the XZ plane, then this would be the Y unit vector, or indeed any vector which, when dotted with Y unit vector, would give a positive result.

    Returns
    Type Description
    System.Single

    The signed angle between the vectors

    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

    System.Single t

    Interpolation amoun t

    Vector3 up

    Defines the up direction

    Returns
    Type Description
    Vector3
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023