Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

point rotation

Status
Not open for further replies.

PZ

Programmer
Jul 21, 2000
18
IT
Is there a way to rotate a point around a given axis in a 3d space? Example: point=P(3,4,5) and the axis is a line from (2,7,6) to (2,8,12). I can't find a way to make point P rotate around that axis! Please help me!<br><br>Thanx in advance! <p> Alex<br><a href=mailto:pizzapz@libero.it>pizzapz@libero.it</a><br><a href= > </a><br>*** Q(uick)BASIC RULEZ! :D***
 
Perhaps, I feel that when you got two Axis, X and a Y its pretty eazy, your Z Axis may be a bit slightly harder. If we look at the Axis, you'll notice X and Y make a cross:<br><br><FONT FACE=monospace><br>&nbsp;&nbsp;¦<br>&nbsp;&nbsp;¦<br>-----<br>&nbsp;&nbsp;¦<br>&nbsp;&nbsp;¦<br></font><br><br>to add a Z Axis, would be to similate depth, in this example, I'm going to make it the Slope of X and Y<br><br><FONT FACE=monospace><br>\ ¦<br>&nbsp;\¦<br>-----<br>&nbsp;&nbsp;¦\<br>&nbsp;&nbsp;¦ \<br></font><br><br>if you can cacluate how to move up and down that third axis (like Y - some Number, and X - some number) I dont know off the top of my head, but you should be able to get a perfect diagonal if you pratice, so then your X,Y,Z is really, an X,Y,(Some Formula to place it similated on an XY Graph)<br><br>did this help somewhat? <p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
I think I didn't explain myself fully, sorry. I'll try again:<br>this is my sub:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zoom = 200<br> depth = 40<br> x2! = (x3d! * COS(rotZ!)) - (y3d! * SIN(rotZ!))<br> y2! = (x3d! * SIN(rotZ!)) + (y3d! * COS(rotZ!))<br> x3! = (x2! * COS(rotY!)) - (z3d! * SIN(rotY!))<br> z2! = (x2! * SIN(rotY!)) + (z3d! * COS(rotY!))<br> y3! = (y2! * COS(rotX!)) - (z2! * SIN(rotX!))<br> z3! = (y2! * SIN(rotX!)) + (z2! * COS(rotX!))<br> x2d% = zoom * (x3! / (z3! + depth)) + (screenwide/2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y2d% = zoom * (y3! / (z3! + depth)) + (screenhigh/2)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pset (x2d%, y2d%), col%<br><br>By modifing rotx!,roty! or rotz! I can rotate a point around the x, y or z axis, but what about an axis that ISN'T x, y or z? <p> Alex<br><a href=mailto:pizzapz@libero.it>pizzapz@libero.it</a><br><a href= > </a><br>*** Q(uick)BASIC RULEZ! :D***
 
you mean how to rotate around only X,y cordinate?, if thats the case, the situation still stands true, you just use zero for the Z Depth, then go from there. <p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
 
Here's a reply from comp.graphics.algorithms on 5 Aug 2000<br>on the same question, which gets asked often.<br><br>The derivation involves quaternions or <br>the definition of 4x4 matrices raised to the nth power.<br>I learned it in school as the 'Rodrigues Formula' and<br>it is briefly mentioned in Computer_Graphics: Principles_and_Practice.<br><br><br>&nbsp;co=cos(alpha) ; si=sin(alpha) ; c1 = 1-cos(alpha)<br>&nbsp;e=(e1,e2,e3) unit vector of the rotation axis<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c1.e1.e1+co&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c1.e1.e2-si.e3&nbsp;&nbsp;&nbsp;&nbsp;c1.e1.e3+si.e2<br>&nbsp;M(alpha,e) =&nbsp;&nbsp;&nbsp;&nbsp;c1.e2.e1+si.e3&nbsp;&nbsp;&nbsp;&nbsp;c1.e2.e2+co&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c1.e2.e3-si.e1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c1.e3.e1-si.e2&nbsp;&nbsp;&nbsp;&nbsp;c1.e3.e2+si.e1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c1.e3.e3+co <br>&nbsp;&nbsp;<br>&nbsp;&nbsp;<br>&nbsp;The quaternion representing this rotation is<br>&nbsp;&nbsp;<br>&nbsp;c = cos(alpha/2)&nbsp;&nbsp;s = sin(alpha/2)<br>&nbsp;&nbsp;<br>&nbsp;q(alpha,e) =&nbsp;&nbsp;( c , s.e1, s.e2, s.e3 )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top