From: Jon Watte <hplus@mi...>  20020228 02:07:16

Because the facing vector is arbitrary, you can choose world space (say, negative Z in a righthanded system). Using that and simple trigonometry (two atan2() calls, mediumexpensive), it's trivial to extract the X & Z rotation angles for Euler angles that will orient a vector pointing down Z to one that points in the direction of the normal. You can also cross the arbitrary facing vector with the normal, which gives you an axis of rotation; then dot them to get the cosine of the rotation angle; Going from axis/cosangle to quaternion or Euler I hope you already have code for, 'cause I'm too lazy to look it up :) Cheers, / h+ > Original Message > From: gdalgorithmslistadmin@... > [mailto:gdalgorithmslistadmin@...]On Behalf Of > Ratcliff, John > Sent: Wednesday, February 27, 2002 3:36 PM > To: gdalgorithmslist@... > Subject: [Algorithms] Oriention from Normal > > > I thought I had this as a solved problem in my code. In fact I was just > going to post a question to the list asking if anyone knew of an > optimization technique. However, now I'm not certain I even have the > problem solved corectly in the first place. > > What I need to be able to do is take the result of an impact > event and then > create a generic orientation, either quaternion or euler, I don't care > which, that can be passed on to other routines like for > generating decals or > oriented effects. > > What my current code does is as follows: > > (1) Take the triangle that was hit and compute it's face normal. > (2) Build a 3x3 rotation matrix from that vector normal, using some > arbitrary 'facing' vector. > (3) Extract the euler rotation from this matrix using the > published graphics > gems sample code routines. > > Now, this isn't necessarily that efficient, and I would certainly be > interested in more direct routes to convert a surface normal into > either an > euler or quaternion rotation that would orient and abitrary object so that > it were aligned with this surface. > > That said, I'm not sure my code, as is, is working correctly. > > Suggestions on more efficient techniques welcome. I assume this is a very > common problem that many people have needed to solve. > > John > > _______________________________________________ > GDAlgorithmslist mailing list > GDAlgorithmslist@... > https://lists.sourceforge.net/lists/listinfo/gdalgorithmslist > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=6188 > 