3D Trig question
May 9, 2007 8:19 AM   RSS feed for this thread Subscribe

3D Trig question: I have a 2D square in 3D space (a Face). I know the positions of the four corner vertices in form x,y,z. How do I calculate the rotation in degrees (Euler angles) as relative from the center of the face? I want to end up with degrees of rotations around x-axis,y-axis,z-axis. Bonus if you can write it in pseudocode.
posted by pooya to computers & internet (7 comments total) 3 users marked this as a favorite
Might Math::SO3 be of use?
posted by dmd at 8:57 AM on May 9, 2007


It's fairly simple to calculate the rotation matrix which takes a square lying in the xy-plane to an arbitrary square in 3D space; it'll just be the orthogonal matrix which takes the two basis vectors (1,0,0) and (0,1,0) to the two unit vectors v1 = (x1, y1, z1) and v2 = (x2, y2, z2) lying along the edges of the desired square. Such a matrix will also take the basis vector (0,0,1) to a vector vn orthogonal to both v1 and v2, which will of course be given by the cross product: vn = v1 × v2.

In other words, your procedure is the following:
  1. Find two vectors v1 and v2 lying along the edges of the square. Normalize them if necessary, so that they have unit length.
  2. Take the cross product of these two vectors to obtain vn.
  3. The desired rotation matrix is then just
    [ x1 x2 xn ]
    [ y1 y2 yn ]
    [ z1 z2 zn ]
I don't know how to do this in terms of Euler angles (which are not, BTW, equivalent to "angles about the x-, y-, and z-axes"), but if all you need is the rotation matrix then this is the easiest way to get it.
posted by Johnny Assay at 8:57 AM on May 9, 2007


How do I calculate the rotation in degrees (Euler angles) as relative from the center of the face?
It's very unclear what you're asking. Particularly the phrase "as relative from the center of the face" is hard to understand.

I think you're asking for a series of rotations (e.g., first about the x-axis, then about the y-axis, then about the z-axis) that would carry a square from some fixed "starting" position to the given position that you're interested in.

Further, it sounds like you want us to envision the origin of the coordinate system at the center of the square, so that the rotations always leave the center point fixed.

Is that all accurate? Having a good statement of the problem will make it easier to get good answers.
posted by Wolfdog at 9:45 AM on May 9, 2007


Yeah, I should say that I assumed in my above instructions that the center of the square was fixed at the origin. If it's not, you'd need to do a translation after you rotated it.
posted by Johnny Assay at 9:47 AM on May 9, 2007


If I've interpreted that correctly, then the calculation can proceed via quaternions.

1. Use Johnny's method to construct a single rotation matrix that accomplishes the transformation.
2. That matrix should have +1 as its only real eigenvalue; take a corresponding unit eigenvector to get the axis of rotation.
3. Construct the components of the corresponding quaternion (described here),
and
4. Get your φ, θ, and ψ (rotation about x-, y-, and z-axes respectively) as described in the next section of the same page.
posted by Wolfdog at 10:06 AM on May 9, 2007


I'm not entirely clear what you're asking but I can't imagine you'd need 3 rotations at all. One is enough to flatten the square into the XY plane and only one more will line it up with the X axis.
posted by chairface at 10:47 AM on May 9, 2007


You don't need three rotations but it is sometimes desirable to express a transformation in a particular decomposition. It is a theorem of Euler that any rotation can be decomposed into successive rotations about the axes, and, in the same way that for example having a complex number in polar form instead of x+yI may be useful, a particular decomposition of a transformation may be called for. You can tell it's called for here because the asker is calling for it.
posted by Wolfdog at 10:54 AM on May 9, 2007


« Older How can I use RFIDs and some s...   |   How can I get a doctor to pres... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
How many balloons would it take to fill a room? July 17, 2007
Algorithm to display a schedule calendar with... April 12, 2007
Land survey freeware sources? January 15, 2007
Postscript code for epicycloid? February 19, 2006
Given the latitude and longitude of three points,... February 6, 2005