Given start point, angles in each rotational axis and a direction, calculate end point

吃可爱长大的小学妹 提交于 2019-11-30 14:09:02

问题


I have a start point in 3D coordinates, e.g. (0,0,0).

I have the direction I am pointing, represented by three angles - one for each angle of rotation (rotation in X, rotation in Y, rotation in Z) (for the sake of the example let's assume I'm one of those old logo turtles with a pen) and the distance I will travel in the direction I am pointing.

How would I go about calculating the end point coordinates?

I know for a 2D system it would be simple:

new_x = old_x + cos(angle) * distance
new_y = old_y + sin(angle) * distance

but I can't work out how to apply this to 3 dimensions

I suppose another way of thinking about this would be trying to find a point on the surface of a sphere, knowing the direction you're pointing and the sphere's radius.


回答1:


Based in the three angles you have to construct the 3x3 rotation matrix. Then each column of the matrix represents the local x, y and z directions. If you have a local direction you want to move by, then multiply the 3x3 rotation with the direction vector to get the result in global coordinates.

I made a little intro to 3D coordinate transformations that I think will answer your question.

3D Coordinates




回答2:


First of all, for positioning a point in 3D you only need two angles (just like you only needed one in 2D)

Secondly, for various reasons (slow cos&sin, gimbal lock, ...) you might want to store the direction as a vector in the first place and avoid angles alltogether.

Anyway, Assuming direction is initially z aligned, then rotated around x axis followed by rotation around y axis.

x=x0 + distance * cos (angleZ) * sin (angleY)

Y=y0 + distance * sin (Anglez)

Z=z0 + distance * cos (angleZ) * cos (angleY)




回答3:


First, it is strange to have three angles to represent the direction -- two would be enough. Second, the result depends on the order in which you turn about the respective axes. Rotations about different axes do not commute.

Possibly you are simply looking for the conversion between spherical and Cartesian coordinates.



来源:https://stackoverflow.com/questions/4642687/given-start-point-angles-in-each-rotational-axis-and-a-direction-calculate-end

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