docs.unity3d.com
    Show / Hide Table of Contents

    Rotate About Axis Node

    Description

    Rotates the input vector In around the axis Axis by the value of Rotation. The unit for rotation angle can be selected by the parameter Unit.

    Ports

    Name Direction Type Binding Description
    In Input Vector 3 None Input value
    Axis Input Vector 3 None Axis to rotate around
    Rotation Input Float None Amount of rotation to apply
    Out Output Vector 3 None Output value

    Controls

    Name Type Options Description
    Unit Dropdown Radians, Degrees Switches the unit for input Rotation

    Generated Code Example

    The following example code represents one possible outcome of this node per Unit mode.

    Radians

    void Unity_RotateAboutAxis_Radians_float(float3 In, float3 Axis, float Rotation, out float3 Out)
    {
        float s = sin(Rotation);
        float c = cos(Rotation);
        float one_minus_c = 1.0 - c;
    
        Axis = normalize(Axis);
        float3x3 rot_mat =
        {   one_minus_c * Axis.x * Axis.x + c, one_minus_c * Axis.x * Axis.y - Axis.z * s, one_minus_c * Axis.z * Axis.x + Axis.y * s,
            one_minus_c * Axis.x * Axis.y + Axis.z * s, one_minus_c * Axis.y * Axis.y + c, one_minus_c * Axis.y * Axis.z - Axis.x * s,
            one_minus_c * Axis.z * Axis.x - Axis.y * s, one_minus_c * Axis.y * Axis.z + Axis.x * s, one_minus_c * Axis.z * Axis.z + c
        };
        Out = mul(rot_mat,  In);
    }
    

    Degrees

    void Unity_RotateAboutAxis_Degrees_float(float3 In, float3 Axis, float Rotation, out float3 Out)
    {
        Rotation = radians(Rotation);
        float s = sin(Rotation);
        float c = cos(Rotation);
        float one_minus_c = 1.0 - c;
    
        Axis = normalize(Axis);
        float3x3 rot_mat =
        {   one_minus_c * Axis.x * Axis.x + c, one_minus_c * Axis.x * Axis.y - Axis.z * s, one_minus_c * Axis.z * Axis.x + Axis.y * s,
            one_minus_c * Axis.x * Axis.y + Axis.z * s, one_minus_c * Axis.y * Axis.y + c, one_minus_c * Axis.y * Axis.z - Axis.x * s,
            one_minus_c * Axis.z * Axis.x - Axis.y * s, one_minus_c * Axis.y * Axis.z + Axis.x * s, one_minus_c * Axis.z * Axis.z + c
        };
        Out = mul(rot_mat,  In);
    }
    
    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