# Affine transformation: rotate a plane parallel to another plane

I am writing a function that extrudes a 2D shape along a 3D spline, as found in 3D modeling software.

I need a way of translating a set of points P so that they all lie in a new plane L (preserving distances between points).

• P is all points where Z = 0;
• L is defined by (0,0,0), with the normal vector N.

I am using Processing, it has common matrix and vector functionality (but no quaternions) A conceptual or pseudo-code answer is OK.

• I just discovered a library for processing that includes quaternion rotation and euler angles. I've been trying to do something similar but looks like I should use this library. github.com/remixlab/proscene – Andy Mac Feb 13 '15 at 7:10

## 1 Answer

I need a way of translating a set of points P

I suppose you mean rotating here?

Let Z = (0,0,1). If cross(N,Z) has length 0, it means that all your points already lie in the desired plane. Otherwise we can build a basis of the target plane:

• U = normalize(cross(N,Z))
• V = cross(N,U)

Now to transform a point P = (x,y,0) so that it lies in your target plane, simply do this:

P2 = x * U + y * V

• does the line V = cross(N,V) contain a typo? V is not defined? Did you mean U? – Andy Mac Feb 17 '15 at 3:41
• oops, yes, it should be U! Fixed. – sam hocevar Feb 17 '15 at 7:00