4

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.

Luka Rahne
  • 10,336
  • 3
  • 34
  • 56

2 Answers2

9

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.

leemes
  • 44,967
  • 21
  • 135
  • 183
BlueRaja - Danny Pflughoeft
  • 84,206
  • 33
  • 197
  • 283
  • I just posted my solution. In you case there are 5 multiplications, 3 sin/cos (for 3 angles) and one acos and one atan function for rotating around 3rd axe, where in mine solution I added just 2 sin/cos and 2 multiplications. Problem is also implementing atan and acos functions in VHDL. – Luka Rahne Mar 12 '11 at 11:09
  • @ralu: Yes, using just the second set of equations for 2D rotation (ignoring the first and third) will work, if you assume the camera is *always* located and oriented on the x-axis. – BlueRaja - Danny Pflughoeft Mar 12 '11 at 17:55
  • Actually you can't rotate about the z-axis by changing φ only. It depends on your current (θ, φ). It makes sense then, that you have to convert to cartesian coordinates to do a rotation about the cartesian axes - in a sense the cartesian axes "aren't there" - you can't "travel along the x-axis" by simple addition in spherical coordinates - so why should you be able to rotate about it? – bobobobo Feb 24 '12 at 19:29
6

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.

Demitri
  • 13,134
  • 4
  • 40
  • 41
cosmosis
  • 6,047
  • 3
  • 32
  • 28
  • 1
    I applied your update to the answer as an edit. I hope you're right, because I didn't verify it :) – leemes Jul 17 '12 at 00:52
  • 1
    I double checked it myself and had another person verify before I posted. Plus, I use it in my work so I better be right. =) – cosmosis Jul 17 '12 at 01:18