Search code examples
pythonnumpyopen3d

How do I transform 3D coordinates to a new normal vector?


I have a series of coordinates, all coplanar to the same plane with a specific normal vector. I have also defined two vectors perpendicular to the normal vector that describe "up/down" and "left/right" within that 3D plane. The center of the plane around which the transformation should take place is also known.

Let's say I have a new normal vector, how would I transform all those 3D coordinates to still be in that plane? So their relative position to the center of the plane with its new normal is still the same?

I have read about a rotation matrix before, but the thing is that I have a vector to transform to, not an angle that describes a rotation, though the plane essentially does make a rotation. I was wondering if there wasn't any method that would make this transformation quick and easy.


Solution

  • So I dug some more into rotation matrices and I found out that you don't necessarily need to know the angle to rotate to that new position.

    Really all you need to do is multiply the rotation matrix with the coordinates relative to the previous rotation matrix. After that you add the coordinates of the point around which you were rotating and there you have it.

    I needed to do this in python and used numpy's matmul method for this. The rotation matrix was made using the vectors that I had already available:

    [[right.x up.x, forward.x],
    [right.y, up.y, forward.y],
    [right.z, up.z, forward.z]]
    

    right, up and forward being 3 vectors of size 1 perpendicular to each other.