How to rotate around the Z axis in 3D

First of all, I am a developer of Flash AS3, but I jump in openframework and have problems using 3D (these examples are in AS)

In 2D, you can simulate an object rotating around a point using Math.Sin() and Math.cos() , for example

 function update(event:Event):void { dot.x = xCenter + Math.cos(angle*Math.PI/180) * range; dot.y = yCenter + Math.sin(angle*Math.PI/180) * range; angle+=speed; } 

I wonder how I would translate this into a three-dimensional orbit if I also wanted to orbit in the third dimension.

 function update(event:Event):void { ... dot.z = zCenter + Math.sin(angle*Math.PI/180) * range; // is this valid? } 

Thanks are welcome.

+4
source share
4 answers

If you rotate around the z axis, you leave a fixed z-coordinate and change the x and y coordinates. So your first code example is what you are looking for .

To rotate around the x axis (or y axis), simply replace x (or y ) with z . Use Cos on the axis you want to be 0 degrees; the choice is arbitrary.

If what you really want is the orbit of an object around a point in 3d space, you will need two angles to describe the orbit: the elevation angle and the angle of inclination. See here and here .
For reference, these equations (where θ and φ are your angles)

x = x 0 + r sin (θ) cos (φ)
y = y 0 + r sin (θ) sin (φ)
z = z 0 + r cos (θ)

+4
source

I would choose two unit perpendicular vectors v, w, which define the plane on which to orbit, then loop over an angle and select the correct ratio of these vectors v and w to construct your vector p = av + bw.

More information is coming.

EDIT:

It may be useful.

http://en.wikipedia.org/wiki/Orbit_equation

EDIT: I think it really is

center + sin (angle) * v * radius1 + cos (angle) * w * radius2

Here v and w are your unit vectors for the circle.

In 2D, they were (1,0) and (0,1).

In 3D, you will need to calculate them - it depends on the orientation of the plane.

If you set radius 1 = radius 2, you get a circle. Otherwise, you should get an ellipse.

+1
source

If you rotate around the Z axis, you just make your first code and leave the Z coordinate as it is.

+1
source

If you just want the orbit to occur on the plane at an angle and not mind that it is elliptical, you can just do something like z = 0.2*x + 0.2*y or any combination that you represent, after you determined the x and y coordinates.

0
source

All Articles