stephie
stephie

Reputation: 121

Transform 3D points to 2D

I have a set of points (x1, x2,..xn) that lie on the plane define by Ax+ By+Cz+d=0. I would like to find the transformation matrix to translate and rotate to XY plane. So, the new point coordinate will be x1'=(xnew, ynew,0).

A lot of answer give quaternion, dot or cross product matrix. I am not sure which one is the correct way.

Thank you

Upvotes: 9

Views: 4241

Answers (1)

andand
andand

Reputation: 17507

First of all, unless in your plane equation, d=0, there is no linear transformation you can apply. You need to instead perform an affine transformation.

One way to do this is to determine an angle and vector about which to rotate to make your pointset lie in a plane parallel to the XY plane (ie. the Z component of your transformed pointset to all have the same values). Then you simply drop the Z component.

For this, let V be the normalized plane normal for the plane containing your points. For convenience define from your plane equation above Ax+By+Cz+d=0:

V = (A, B, C)
V' = V / ||V|| = (A', B', C')
Z = (0, 0, 1)

where

A' = A / ||V||
B' = B / ||V||
C' = C / ||V||
||V|| = (A2+B2+C2)1/2

The angle will simply be:

θ = cos-1(ZV / ||V||)
  = cos-1(ZV')
  = cos-1(C')

The axis R about which to rotate is just the cross product of the normalized plane normal V' and Z. That is

R = V'×Z
  = (B', -A', 0)

You can now use this angle / axis pair to build the quaternion rotation needed to rotate all of the points in your dataset to a plane parallel to the XY plane. Then, a I said earlier, just drop the Z component to perform an orthogonal projection onto the XY plane.

Update: antonakos makes a good point about normalizing the R before using an API taking axis / angle pairs.

Upvotes: 8

Related Questions