Rotating body from spherical coordinates

烈酒焚心 提交于 2021-01-21 09:18:19

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5278417/rotating-body-from-spherical-coordinates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!