Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotating body from spherical coordinates

Is it possible to rotate body which has its vertices defined in spherical coordinates. Currently I am doing collage project in VHDL and is about rotating dodecahedron and presenting over VGA.

I applied pinhole camera model equations and that required just two sin/cos calculation and two multiplication per vertice. I was just thinking about rotating around 3rd axis using 3 steps over two angles but i am unable to figure out proper equations and even if this is possible.

Edit

I think I got it.

Rotating over 3rd axis which is in same direction as camera is just 2D transform of camera coordinates once you you compute them. That mean than for rotating in 3 axes (ok two axis and one inclination) you need to apply total of 4 sin/cos computations and 4 multiplications. If somebody came up whit something better, fell free to post answer.

like image 869
Luka Rahne Avatar asked Dec 13 '22 15:12

Luka Rahne


2 Answers

You can rotate around the y-axis by changing θ, and rotate around the z-axis by changing φ. Rotating around the x-axis, though, is a bit tougher.

One simple way would be to convert everything to catesian coordinates, perform the rotation, and convert back.

The equations for (x,y,z) (spherical-to-cartesian) are

x = r sin θ cos φ
y = r sin θ sin φ
z = r cos θ

The equations for rotating (x,y,z) to new points (x', y', z') around the x-axis by an angle α are

x' = x
   = r sin θ cos φ
y' = y cos α - z sin α
   = (r sin θ sin φ) cos α - (r cos θ) sin α
z' = y sin α + z cos α
   = (r sin θ sin φ) sin α + (r cos θ) cos α

The equations for (r, θ, φ) (cartesian-to-spherical) are

r' = sqrt(x'2 + y'2 + z'2)
   = r
θ' = cos-1(z'/r')
   = cos-1(sin θ sin φ sin α + cos θ cos α)
φ' = tan-1(y'/x')
   = tan-1(tan φ cos α - cotan θ sin α sec φ)

I don't know if there is a way to reduce that any further, but it should work.

like image 103
BlueRaja - Danny Pflughoeft Avatar answered Feb 20 '23 06:02

BlueRaja - Danny Pflughoeft


Hopefully this will be helpful to someone in the future, but there is a small mistake in the above answer. It should be:

φ' = tan-1(y'/x')
   = tan-1(tan φ cos α - cotan θ sin α sec φ)

I don't have the rep points to post this in the comment, but thought it would be useful.

like image 23
cosmosis Avatar answered Feb 20 '23 06:02

cosmosis