rotating objects around given line

over 5 years ago malczak math, opengl, graphics comments

if one wants to rotate objects around specified line in the space, one will have to gine two different points lying on that line. what is equivalent to giving normalized vector in the space. in OpenGl there are two ways of doing this :
1. transform coordinate system, so that one of its axis coincides with rotatation line. aftewards one will rotate object around selected axis, one that is coincide with rotation line
2. transform whole object, so that rotation can be realized without transforming the coordinate system

whats the difference ? the first reailzation can be useful when using objects like gluQuadrics (e.g. gluSphere). Whereas the other idea can be 'better' for rotating objects, for which one knows all vertices. there is one question, is method 2 realy better than method 1 ? using method 2 one must make some calculations to rotate all vertices of the object. when rotated object is drawn all vertices are then multiplied by current transformation matrix (ctm). while in method 1 all vertices are multiplied only by ctm.

the first of them is very simillar to the idea from previous post, so ill skip it. to talk about the second one, ill assume that one wants to rotate objects arount line defined by vector n=[nx,ny,nz], where |n|=1, with beginning in origin of cs. to rotate a single point p=(px,py,pz), defined in XYZ coordinate system, around given line one must transform point to p' defined in X'Y'Z', where axis Y' is coincide with vector n. once one do this, one must rotate point p' around the axis Y', so that we get new point p''. afterwards we can finally express point p'' in XYZ coordinate system (so that one can get final point called f). and thats all... using matrix algebra we can write that :
img16.gif
where M - is matrix of transformation from XYZ cs to X'Y'Z' cs, R(alpha,Y) is rotation matrix around axis Y, M^(-1) is inverse of matrix M.

Matrix M is created more or less like in previous post that is by multiplication of two matrices (lets call them R1, R2), these are rotation matrices that transforms our point to new cs. so whole transformation can be defined as :

img17.gif



note the proper order of multiplications, that is from left to right. moreover if one calculates above equation like img18.gif one would not get the proper effect !!!! and thats, all... time for image. the red circle has been rotated around yellow line giving us a torus rotation.png

Comments

No comments as yet. Be first to comment.

New comment

  1. (with http or https prefix)

  2. (use [code][/code] tags to post a code snippet)

  3. (javascript is required)

Website content premeditately commited by malczak & sobstel.
Layout by mlando. Icons by dryicons.com. All rights reserved.