----- Original Message ----- From: "Bob Dengle" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Saturday, March 09, 2002 2:04 PM Subject: Re: [JAVA3D] Rotations
> Hi > When you use this method to construct the axisangle with two arbitrary > vectors, I've found that sometimes the rotation angle will not be the > correct one. For example, suppose you have two unit vectors, one along the > positive x-axis (v1) and one along the positive y-axis (v2). I wish to find > the transform that will turn v1 into v2. When you find the angle it will > always be PI/2. However, depending on the order you put the vectors, > (v1.cross(v2) or v2.cross(v1)) the axis for your rotation will either be a > unit vector on the positive z-axis, or a unit vector along the negative > z-axis. In the first case, the angle should be PI/2, but in the second case > the angle should be -PI/2. > Is there a way to determine the proper axis-angle set for two arbitrary > vectors? the way I do it now is to simply build the transform3ds and check > to see which will transform the vector correctly, and im sure there is a > more efficient way to do it. It seems that it's always a struggle to figure out how the principal values are reflected in the math package of your choice, and my experience has been that I eventually end up doing exhaustive, quadrant-by-quadrant tests. I suspect that, in this particular case, you can avoid some of the problems by side-stepping the arccos() and going directly to the quaternion. > >1. Points are P1 and P2 > >2. length of cylinder L = |P2 - P1| > >3. desired unit vector along axis of cylinder V = (P2 - P1)/L > >4. midpoint of line M = (P1 + P2)/2> > . . . > >5. Construct cylinder Shape3D cyl = new Shape3D . . . > > I forget what axis the Java 3D primitive Cylinder lines up on, say it's the > > X-axis, X. > > . . . > >7. Find rotation axis S = X cross V; // don't normalize it here. Transform3D t3d = new Transform3D(new Quat4d(S.x, S.y, S.z, X dot V), new Vector3d(M), 1.0); I haven't run a sample problem to verify this so YMMV. hth, Fred Klingener Brock Engineering =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".