## RE: [Algorithms] Oriention from Normal

 RE: [Algorithms] Oriention from Normal From: Ratcliff, John - 2002-02-28 00:18:06 ```Hmmmm..how about just doing this? At least that's why our new AI guy, Scott Martin, added to our math libraries today: euler.x = 0; // roll euler.y = acosf(normal.z); // pitch euler.z = atanf(normal.y, normal.x); // yaw ??? If you are going to be working in euler co-ordinates as a generalized representation that is. And going from euler to quat is easy enough. John -----Original Message----- From: Chris Butcher (BUNGIE) [mailto:cbutcher@...] Sent: Wednesday, February 27, 2002 6:00 PM To: gdalgorithms-list@... Subject: RE: [Algorithms] Oriention from Normal > -----Original Message----- > From: Ratcliff, John [mailto:jratcliff@...] > > 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. > If I understand you correctly, you're looking for a quaternion that will rotate a Z-axis-aligned object to face along a given vector. Take the cross product of this vector with +Z to get a rotation axis, and the dot product of this vector with +Z (i.e. the Z component of the vector) to give the cosine of the angle of the rotation. That gives you an axis a and a rotation magnitude cos(theta). Use trigonometric identities to generate cos(theta/2) and sin(theta/2). You can build the quaternion directly as: q.w = cos(theta/2) q.v = sin(theta/2)*normalize(a) The only real problem with this is that there's no control over the 'roll' component of the rotation. If you wanted to modify that (e.g. by randomizing it) you could premultiply by a random quaternion that is a rotation about +Z. -- Chris Butcher AI Engineer | Halo Bungie Studios butcher@... _______________________________________________ GDAlgorithms-list mailing list GDAlgorithms-list@... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_ida88 ```

 RE: [Algorithms] Oriention from Normal From: Chris Butcher (BUNGIE) - 2002-02-28 00:01:28 ```> -----Original Message----- > From: Ratcliff, John [mailto:jratcliff@...] >=20 > 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. >=20 If I understand you correctly, you're looking for a quaternion that = will rotate a Z-axis-aligned object to face along a given vector. Take the cross product of this vector with +Z to get a rotation axis, = and the dot product of this vector with +Z (i.e. the Z component of the = vector) to give the cosine of the angle of the rotation. That gives you an axis a and a rotation magnitude cos(theta). Use = trigonometric identities to generate cos(theta/2) and sin(theta/2). You = can build the quaternion directly as: q.w =3D cos(theta/2) q.v =3D sin(theta/2)*normalize(a) The only real problem with this is that there's no control over the = 'roll' component of the rotation. If you wanted to modify that (e.g. by = randomizing it) you could premultiply by a random quaternion that is a = rotation about +Z. -- Chris Butcher AI Engineer | Halo Bungie Studios butcher@... ```
 RE: [Algorithms] Oriention from Normal From: Ratcliff, John - 2002-02-28 00:18:06 ```Hmmmm..how about just doing this? At least that's why our new AI guy, Scott Martin, added to our math libraries today: euler.x = 0; // roll euler.y = acosf(normal.z); // pitch euler.z = atanf(normal.y, normal.x); // yaw ??? If you are going to be working in euler co-ordinates as a generalized representation that is. And going from euler to quat is easy enough. John -----Original Message----- From: Chris Butcher (BUNGIE) [mailto:cbutcher@...] Sent: Wednesday, February 27, 2002 6:00 PM To: gdalgorithms-list@... Subject: RE: [Algorithms] Oriention from Normal > -----Original Message----- > From: Ratcliff, John [mailto:jratcliff@...] > > 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. > If I understand you correctly, you're looking for a quaternion that will rotate a Z-axis-aligned object to face along a given vector. Take the cross product of this vector with +Z to get a rotation axis, and the dot product of this vector with +Z (i.e. the Z component of the vector) to give the cosine of the angle of the rotation. That gives you an axis a and a rotation magnitude cos(theta). Use trigonometric identities to generate cos(theta/2) and sin(theta/2). You can build the quaternion directly as: q.w = cos(theta/2) q.v = sin(theta/2)*normalize(a) The only real problem with this is that there's no control over the 'roll' component of the rotation. If you wanted to modify that (e.g. by randomizing it) you could premultiply by a random quaternion that is a rotation about +Z. -- Chris Butcher AI Engineer | Halo Bungie Studios butcher@... _______________________________________________ GDAlgorithms-list mailing list GDAlgorithms-list@... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_ida88 ```
 RE: [Algorithms] Oriention from Normal From: Chris Butcher (BUNGIE) - 2002-02-28 01:58:35 ```> -----Original Message----- > From: Ratcliff, John [mailto:jratcliff@...] > Sent: Wednesday, February 27, 2002 16:18 > To: Chris Butcher (BUNGIE); gdalgorithms-list@... > Subject: RE: [Algorithms] Oriention from Normal >=20 > Hmmmm..how about just doing this? At least that's why our new AI guy, = Scott > Martin, added to our math libraries today: >=20 > euler.x =3D 0; // roll > euler.y =3D acosf(normal.z); // pitch > euler.z =3D atanf(normal.y, normal.x); // yaw >=20 > ??? >=20 > If you are going to be working in euler co-ordinates as a generalized > representation that is. And going from euler to quat is easy enough. >=20 Sure, that works, although it's almost certainly slower. Be very wary = of slightly-out-of-range values in normal.z if you're passing it to = acosf directly. -- Chris Butcher AI Engineer | Halo Bungie Studios butcher@... ```