I try to make this as clear as possible:
I place an object at the center (0,0,0) of the scene. Then I place a camera given a fix radius on a hemisphere around the object (and use Constraints to make it always look at the object) and render the image. I export the object as .stl with y-up and minus-z-forward, in order to open it with another library that uses this different convention.
I would like to rotate the object in such a way that it would correspond to the view of the rendered image.
The angles for azimuth and elevation are known. So I calculate the rotation matrix given the two angles (I need a homogeneous rotation matrix, thus appending the 0s and 1).
def angles_to_matrix(phi, theta): # phi describes the azimuth azi = phi # theta describes the inclination angle, thus: ele = radians(90) - theta rol = 0 e1 = cos(rol) * cos(azi) - sin(rol) * cos(ele) * sin(azi) e2 = sin(rol) * cos(azi) + cos(rol) * cos(ele) * sin(azi) e3 = sin(ele) * sin(azi) e4 = -cos(rol) * sin(azi) - sin(rol) * cos(ele) * cos(azi) e5 = -sin(rol) * sin(azi) + cos(rol) * cos(ele) * cos(azi) e6 = sin(ele) * cos(azi) e7 = sin(rol) * sin(ele) e8 = -cos(rol) * sin(ele) e9 = cos(ele) return np.array(((e1, e2, e3, 0), (e4, e5, e6, 0), (e7, e8, e9,0 ), (0, 0, 0, 1)))
The rotation does not look right. & I feel there could be several things going wrong:
- Did I miss something concerning the change of axis orientation?
- Is it even possible to use the same angles for calculating the sphere coordinates to calculate the rotation of the object?
Do you have any ideas?