Calculate the pose of a point on the sphere pointing to the center of the sphere

Background: Recently, there is a need to use a camera to take pictures of an object. In the initial state, the camera is directly above the object, and then the coordinates of the camera change according to a certain rule, requiring its field of view center to always be fixed on the object. This problem can be understood as: establish a coordinate system with the item, and the attitude of the camera in this space is [x,y,z, α \alphaa ,b \betab ,γ \gammagamma ]. Among them, X, Y, and Z are the coordinates of the camera in the object coordinate system,α \alphaab \betabc \gammaγ is the angle of rotation of the camera around the three axes. And X, Y, Z are known quantities,α \alphaab \betabc \gammaγ is the quantity to be demanded.

Regarding the problem of finding the angle, it can be converted to the problem of the angle of the sphere:

insert image description here
For a point on a sphere, we can express it in a three-dimensional Cartesian coordinate system, but also in a spherical coordinate system. Suppose the initial coordinates of a point on the sphere are in [0,0,r], where rrr is the radius of the sphere. Then we can turn the point to any position on the sphere by two rotations, so the representation of the point is: [rrrϕ \phiϕ θ \theta θ]。 r r r is the distance from the spherical coordinate point to the center of the sphere;ϕ \phiϕ is the angle measured counterclockwise starting from the x-axis on the equatorial plane (the plane determined by the x-axis and y-axis);θ \thetaθ is the angle between the z axis and r.

Going back to the original question, the question can be understood as: In the initial state, the camera's attitude is [0, 0, 0, 3.14, 0, 0], that is, the camera is directly above the Z axis, and the camera's Z axis is facing down . Then if we need to turn the camera to [ rr on the sphere at this timerϕ \phiϕ θ \theta θ ] position, the new angle value of the camera is [3.14+θ \thetaθ , 0,ϕ \phiϕ ], so that we can know the pose of the camera relative to the object.

Then the next step is to find out ϕ \phiϕ θ \theta Two angles of θ are enough, according to the relationship between the representation method of the three-dimensional rectangular coordinate system and the representation method of the spherical coordinate system: {
x = rsin θ cos φ , y = rsin θ sin φ , z = rcos θ \begin{cases} x=rsinθcosφ, \\ y=rsinθsinφ, \\ z=rcosθ \end{cases} x=rs in θ cos φ ,y=rs in θ s in φ ,z=rcosθ

It can be seen that when the coordinates [X, Y, Z] of a point on the sphere are known, the rotation angle around the two axes can be calculated according to the above formula: { θ = arccos ( z / r ) φ =
arcsin ( y / ( rsin θ ) ) \begin{cases} θ=arccos(z/r) \\ φ=arcsin(y/(rsinθ)) \end{cases}{ i=arccos(z/r)Phi=a rcs in ( y / ( rs in θ ) )
According to the above formula, it can be known that the camera pose at any position is: [X, Y, Z, 3.14+ θ \thetaθ , 0,ϕ \phiϕ ].

Publish the results according to TF:
insert image description here
insert image description here

It can be seen that although the position of the camera is always changing, the Z axis of the camera is always pointing to the center of the circle, which can meet the initial requirements.

reference:

Mind-only Consciousness 061·A Brief Introduction to the Spherical Coordinate System

Guess you like

Origin blog.csdn.net/YiYeZhiNian/article/details/131975626