Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Circular rotation around an arbitrary axis

Tags:

I am programming Starcraft 2 custom maps and got some proglems with math in 3D. Currently I am trying to create and rotate a point around an arbitrary axis, given by x,y and z (the xyz vector is normalized).

I've been trying around a lot and read through a lot of stuff on the internet, but I just cant get how it works correctly. My current script (you probably dont know the language, but it's nothing special) is the result of breaking everything for hours (doesn't work correctly):

    point CP; fixed AXY; point D; point DnoZ; point DXY_Z; fixed AZ; fixed LXY; missile[Missile].Angle = (missile[Missile].Angle + missile[Missile].Acceleration) % 360.0; missile[Missile].Acceleration += missile[Missile].AirResistance; if (missile[Missile].Parent > -1) {     D = missile[missile[Missile].Parent].Direction;     DnoZ = Point(PointGetX(D),0.0);     DXY_Z = Normalize(Point(SquareRoot(PointDot(DnoZ,DnoZ)),PointGetHeight(D)));     AZ = MaxF(ACos(PointGetX(DXY_Z)),ASin(PointGetY(DXY_Z)))+missile[Missile].Angle;     DnoZ = Normalize(DnoZ);     AXY = MaxF(ACos(PointGetX(DnoZ)),ASin(PointGetY(DnoZ)));     CP = Point(Cos(AXY+90),Sin(AXY+90));     LXY = SquareRoot(PointDot(CP,CP));     if (LXY > 0) {         CP = PointMult(CP,Cos(AZ)/LXY);         PointSetHeight(CP,Sin(AZ));     } else {         CP = Point3(0.0,0.0,1.0);     } } else {     CP = Point(Cos(missile[Missile].Angle),Sin(missile[Missile].Angle)); } missile[Missile].Direction = Normalize(CP); missile[Missile].Position = PointAdd(missile[Missile].Position,PointMult(missile[Missile].Direction,missile[Missile].Distance)); 

I just cant get my mind around the math. If you can explain it in simple terms that would be the best solution, a code snipped would be good as well (but not quite as helpful, because I plan to do more 3D stuff in the future).

like image 337
Alexander Avatar asked Jul 17 '11 02:07

Alexander


People also ask

How do you rotate around an arbitrary axis?

Rotate space about the x axis so that the rotation axis lies in the xz plane. Let U = (a,b,c) be the unit vector along the rotation axis. and define d = sqrt(b2 + c2) as the length of the projection onto the yz plane. If d = 0 then the rotation axis is along the x axis and no additional rotation is necessary.

How do you rotate an object about an arbitrary point?

Rotation about an arbitrary point: If we want to rotate an object or point about an arbitrary point, first of all, we translate the point about which we want to rotate to the origin. Then rotate point or object about the origin, and at the end, we again translate it to the original place.

What is arbitrary rotation?

The Arbitrary Rotation command rotates a layer by a specified angle. It is an alternate way of accessing the Rotate tool.

What is meant by arbitrary axis?

“Arbitrary” means you may choose the axis of rotation any way you like. So simply choose any line in space, and then put a pin into your object along that line, and rotate the object around the pin.


1 Answers

http://en.wikipedia.org/wiki/Rotation_matrix. Look under the section Rotation matrix from axis and angle. For your convenience, here's the matrix you need. It's a bit hairy. theta is the angle, and ux, uy, and uz are the x, y, and z components of the normalized axis vector

Here's the rotation matrix

If you don't understand matrices and vectors, post back and I'll help you.

like image 188
Gravity Avatar answered Sep 18 '22 09:09

Gravity