Search code examples
c#unity-game-engineaxisanglequaternions

How to calculate the angle given a quaternion rotation and a specified axis?


I'm trying to rotate an object around only one axis (any arbitrary unit vector, not necessarily x, y or z), based on the quaternion rotation component along the same axis of a specified quaternion rotation.

public void Rotate(Quaternion rotation, Vector3 axis, Vector3 pointToRotateAround)
{
     float angle = ?
     gameObject.transform.RotateAround(pointToRotateAround, axis, angle);
}

I don't know how to obtain the angle of my quaternion's rotation that is only along the specified axis. I could do it when the axis is y, for example:

public void Rotate(Quaternion rotation, Vector3 pointToRotateAround)
{
     gameObject.transform.RotateAround(pointToRotateAround, Vector3.up, rotation.eulerAngles.y);
}

I want to replicate the results of the above, but for any given axis.

I've dug into google trying to find the answer to this but I haven't found a solution. Any help is appreciated.


Solution

  • The way I am interpreting your question is that if you have a set of rotating points, by what angle would they move around some other axis.

    The only issue with this is that the angle from a different axis actually depends on which point you are looking at.

    Rotation

    However, something you could try is to represent your rotation as an axis angle (ω, θ), then take the dot product with your axis v to get a new angle of θ scaled by w.v. This might not be what you want , but if you add details with more details on what you are trying to achieve, we might be able to help you better.