# Rotating a Vector3's coordinates based on a Quaternion???

Hello,
How would I rotate a Vector3’s position based on a Vector3 pivot point using a Quaternion or Euler rotation from the pivotal point? I don’t want to have to create an object and attach a child and destroy the object in order to do this, and would just like the new Vector3 coordinates returned from a function. I think the Unity developers should invent some functions called…

Vector3.RotateFromPivot(point : Vector3, pivot : Vector3, rotation : Quaternion) : Vector3

Vector3.RotateFromPivot(point : Vector3, pivot : Vector3, eulerRotation : Vector3) : Vector3

and

Vector2.RotateFromPivot(point : Vector2, pivot : Vector2, angle : float) : Vector2

In the next version of Unity.
Thank you,
Michael S. Lowe

To get the rotation around an axis

then just do
rotatedPoint = rotation * oldPoint

1 Like

That returns a quaternion angle. What I am looking for is a new Vector3 position that got rotated from an old Vector3 position based on a pivotal point where the pivot got rotated through either a quaternion or a Euler rotation, and to do this without having to attach any children to any empty objects while using transform rotations and then detaching the child and destroying the parent in order to figure out my new Vector3 position.

It would make things a whole lot easier if Unity had some built-in functions (like the 3 functions above) that would quickly calculate a new Vector3 position without having to use transforms.

I’m better in C#, though I’m sure you can convert this to UnityScript easy. NOT TESTED (I hope I’m right about this!)

``````public static Vector3 RotateFromPivot(Vector3 point, Vector3 pivot, Quaternion rotation)
{
return pivot + (rotation * (point - pivot));
}

public static Vector3 RotateFromPivot(Vector3 point, Vector3 pivot, Vector3 eulerRotation)
{
return RotateFromPivot(point, pivot, Quaternion.Euler(eulerRotation);
}

public static Vector2 RotateFromPivot(Vector2 point, Vector2 pivot, float angle)
{
return RotateFromPivot(point, pivot, angle * Vector3.forward);
}
``````

Here’s that first function expanded out into the steps I took to obtain it.

``````public static Vector3 RotateFromPivot(Vector3 point, Vector3 pivot, Quaternion rotation)
{
// Direction vector from pivot to point
Vector3 directionVector = point - pivot;
Vector3 rotatedDirectionVector = rotation * directionVector;
Vector3 rotatedPoint = pivot + rotatedDirectionVector;
return rotatedPoint;
}
``````

Thank you. It works.

1 Like