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.
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
No comments:
Post a Comment