RE: [Algorithms] Rotation about arbitrary axis
Brought to you by:
vexxed72
From: Matthew D. <MD...@ac...> - 2000-08-21 18:05:21
|
Hi Pierre, I wrote some code for just that purpose not so long ago: inline void matrix::SetRotation (const vector &axis, f32 radians) { f32 s, c, t; Maths_SinCos(radians,s,c); // Calculate sin and cosine t = 1 - c; assert(axis.IsValid()); f32 txy = t*(axis.x * axis.y); f32 tyz = t*(axis.y * axis.z); f32 txz = t*(axis.x * axis.z); f32 xs = axis.x * s; f32 ys = axis.y * s; f32 zs = axis.z * s; _14 = _24 = _34 = _41 = _42 = _43 = 0.0f; _44 = 1.0f; _11 = t*(axis.x*axis.x) + c; _22 = t*(axis.y*axis.y) + c; _33 = t*(axis.z*axis.z) + c; _12 = txy + zs; _13 = txz - ys; _21 = txy - zs; _23 = tyz + xs; _31 = txz + ys; _32 = tyz - xs; } I'm sure you can adapt that code. For 4x4 matrices just extend it: A B C A B C 0 D E F D E F 0 G H I G H I 0 0 0 0 1 Best regards, Matt. > -----Original Message----- > From: Pierre Terdiman [mailto:p.t...@wa...] > Sent: Monday, August 21, 2000 17:58 > To: gda...@li... > Subject: [Algorithms] Rotation about arbitrary axis > > > Hi, > > Since I needed a piece of code to do that I searched the web > and found: > http://www.iuk.tu-harburg.de/hypgraph/modeling/mod_tran/3drota.htm > > I used the final matrix at the bottom of the page, but it > seems to fail when > the arbitrary axis actually is the Z axis. The third column > gets erased > where it should at least contain a 1. This is obvious when > looking at the > provided matrix, since the third column of the third row > depends on the > rotation angle - and of course if the input axis already is > the Z axis, it > shouldn't. > > Now, it sounds normal regarding the underlying method > (mapping the rotation > axis to Z, etc). But I wonder whether there's an easy way to > perform a real > arbitrary rotation about any arbitrary axis without using > different code > paths according to the input axis. > > I think it can probably be done by introducing quaternions or better, > angle-axis, in the story. But err.... maybe there's something simpler. > > Pierre > > > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > http://lists.sourceforge.net/mailman/listinfo/gdalgorithms-list > |