I am trying to rotate a 3D Cylinder with reference to a 2D viewport. With the radius of the cylinder and the 2D translation known, how can i find out the angle it turns?
Let's assume the cylinder rotates from A to B. Further, let's assume that A is θ
degrees counterclockwise and B is θ
degrees clockwise from the horizontal. Thus, the angle between A and B is 2θ
.
The y coordinate of A is given by r*sin(θ)
, that of B is simply -r*sin(θ)
.
Thus, 2*r*sin(θ) = D
(the pan distance)
Solve for θ
:
θ = asin(D/(2*r))
(where asin is the arc sine function)
Another (possibly more robust) method would be to compute the perpendicular and base of the triangle and then do an atan2(perp,base)
.
The perpendicular is simply D/2
, while the base is sqrt(R*R - D*D/4)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.