Pane Rotation - Computer Graphics
Date: 11/14/96 at 16:14:15 From: Bart Subject: Rotating a pane in 3d space Dear Dr. Math: Hello! I am looking to see if anyone can help me solve a math problem that I have self-imposed :-). It has to do with 3d vectors. All right, let's say you have a pane in 3d space defined by four points. You can rotate it using variables rx, ry, and rz. The rotation formula is as follows: (The formula has to be used for all the points with the same rx, ry, rz values) s1 = SIN(ry) s2 = SIN(rz) s3 = SIN(rx) c1 = COS(ry) c2 = COS(rz) c3 = COS(rx) rotated x = x(s1s2s3 + c1 * c3) + y(c2s3) + z(c1s2s3 - c3s1) rotated y = x(c3s1s2 - c1s3) + y(c2c3) + z(c1c3s2 + s1s3) rotated z = x(c1s2s3 - c1s1) + y(-s2) + z(c1c2) Using the right values, you can rotate the pane so that all of the rotated z values are equal and the pane is flat in front of you. Now, what I would just love to have is a formula that computes the correct rx, ry, and rz values to make the Z's equal! Any help will be greatly appreciated! Thanks in advance.
Date: 11/19/96 at 18:10:00 From: Doctor Tom Subject: Re: Rotating a pane in 3d space them Hi Bart, It's a little hard to guess exactly what your rx, ry, and rz stand for geometrically, and solving the equations by brute force would be a pretty ugly proposition. However, I can tell you how this sort of thing is done in computer graphics. First off, you don't want to deal with the points on the corners of the pane. Instead, you want to deal with a vector that's perpendicular to the pane and rotate that vector until it lines up with the z-axis. If p0, p1, and p2 are three of the four corners, then p0-p1 and p1-p2 are vectors parallel to the edges. The cross product of those differences will be perpendicular to the pane. To make the problem concrete, I'll also assume that after the rotation, you want to have the edges of the pane parallel to the x and y axes. Let n = (p0-p1)x(p1-p2) be the perpendicular vector. "Normalize" n to make it have length 1 by dividing its components by its length. Let N be the normalized n. Similarly, normalize p0-p1 (giving P) and normalize p1-p2 (giving Q). So the goal is to rotate the triple of vectors P, Q, and N to (1,0,0), (0,1,0), and (0,0,1). I'll write P = (px,py,pz), Q = (qx,qy,qz) and N = (nx,ny,nz). We need to find a 3 by 3 matrix M so that: | px py pz | | 1 0 0 | | qx qy qz | M = | 0 1 0 |. | nx ny nz | | 0 0 1 | M is just the inverse of the matrix on the far left, and will be a pure rotation matrix. -Doctor Tom, The Math Forum Check out our web site! http://mathforum.org/dr.math/
Search the Dr. Math Library:
Ask Dr. MathTM
© 1994-2013 The Math Forum