I've been stuck on this forever now because I don't understand math in the slightest and when people talk about matrices they just give the table and don't explain how to actually go through each step.

My question is how do I rotate a point around a pivot by moving the axis instead of the point.rotationaroundaxis

        Vector3 center = new Vector3(0.5f,0.5f,0.5f); //an arbitrary center
        Vector3 point = new Vector3(0.5f, 0.5f, 0); //an arbitrary point
        Vector3 endpoint; //how do I get this

        Vector3 current_east = Vector3.right;  //x
        Vector3 current_up = Vector3.up; //y
        Vector3 current_north = Vector3.forward; //z

        Vector3 moveto_east = Vector3.back;
        Vector3 moveto_up = Vector3.left;
        Vector3 moveto_north = Vector3.up;

So if I was to rotate the current vectors, to the moveto vectors what position would the point be in. (in this case it would be 0.5, 0, 0.5) buut how would I achieve this assuming the point and the axis will be arbitrarily defined. Picture for clarification.


1 Answer 1


Ah, linear algebra. Few things that probably no one told you, but are pretty essential to understand matrices and rotations (i hope i don't mix the names, never learned maths in english).

  1. Each point in space has a position, dependent on the basis you defined (you know, the perpendicular arrows starting at [0, 0])

  2. Each column of the rotation matrix defines single arrow of your basis. For 'unrotated' world (rotation matrix is identity matrix), your X axis is in direction [1, 0] and Y in [0, 1].

  3. If you want to rotate a point around the orgin of your basis, you effectively define new basis with rotated axes. If you want to rotate 90 degrees, your new X axis will be [0, 1] and Y will be [-1, 0]. Putting them into matrix (as columns), will give us matrix (which matches the formula from https://en.wikipedia.org/wiki/Rotation_matrix ):

     [0 -1]
     [1  0]
  4. To perform the rotation you have to multiply the rotation matrix by the vector (point's coordinates). To undo the rotation you have to multiply the rotation matrix inverse by the rotated point. Calculation of matrix inverse generally is difficult. There's a trick however. If basis is orthogonal (which simply means all axes are perpendicular to each other, and that's the case most of the time in 2D/3D graphics), then matrix inverse is its transposition (columns become rows). Inverse of above rotation matrix will become:

    [ 0 1]
    [-1 0]
  5. To rotate a point A around an arbitrary point B using matrix M, you have to:

    1. Define B as the origin of your basis (this will give us point A'; to do that simply subtract B from A)
    2. Rotate A' using M (multiply M by A')
    3. Restore the original origin (add B)

    In matemathical terms it will be B+M*(A-B)

If i understand correctly, you want to rotate a point A around B starting from rotation M1 (current_*) to rotation M2 (moveto_*). Matrices M1 and M2 are created from your east/up/north vectors (they become the columns of the matrices). So:

  1. Define B as the origin (subtract B),
  2. Undo the current rotation (multiply inverse of M1)
  3. Perform moveto rotation (multiply M2)
  4. Restore origin (add B)

Mathematically this will be: B+M2*transpose(M1)*(A-B)

(Hopefully i didn't mix anything, and my memory didn't fail me)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .