I know two 3D-points in a line (top and bottom of an unsymmetrical object), and would like to find euler angles(rotation along x, y and z axis).
Example: Need reverse engineering of following code of OpenGL, below is the just an example to show the scenario.
//Translation
glTranslated(p1.x, p1.y, p1.z);
//Rotation
glRotatef(rot.x, 1.0f, 0.0f, 0.0f);
glRotatef(rot.y, 0.0f, 1.0f, 0.0f);
glRotatef(rot.z, 0.0f, 0.0f, 1.0f);
// Draw the object ALONG Y-AXIS
p2 = DrawMyObject(); //p2 is top of my object
Now in some situations I got only p1 and p2 and I need to know euler angles (roation along x, y and z axis). How?
This is what I tried and answer should be (Rx, Ry, Rz): (4, -3, -11),
cv::Point3d p1, p2;
p1.x = 0.0525498;
p1.y = 0.0798909;
p1.z = -1.20806;
p2.x = 0.0586557;
p2.y = 0.111226;
p2.z = -1.20587;
double dx, dy, dz;
double angle;
dx = p2.x - p1.x;
dy = p2.y - p1.y;
dz = p2.z - p1.z;
angle = std::atan2(dy, dz); angle = RAD2DEG(angle);
std::cout<<"\n atan2(dy, dz): "<<int(90 - angle);
angle = std::atan2(dx, dz); angle = RAD2DEG(angle);
std::cout<<"\n atan2(dz, dx): "<<angle;
angle = std::atan2(dy, dx); angle = RAD2DEG(angle);
std::cout<<"\n atan2(dy, dx): "<<int(angle -90);
std::cout<<std::endl;
I am not getting exactly correct answer, especially rotation along Y is not correct at all. I think p1 and p2 both lies in y-axis while rotating along y-axis so the problem is. Then what is best possible solution?