I'd like to get the inclination of a point from the camera's plane of rotation (defined by the local y-axis).
The code I currently have to works sometimes, but not always. It works when the camera is at the global origin, but not always otherwise. Here I have a point
of type Vector
, and a camera.
import math
camera = ...
point = ...
point_in_local_coords = ( camera.matrix_world.inverted() * point )
angle_to_normal = Vector( (0,1,0) ).angle( point_in_local_coords )
angle_to_plane_of_rotation = math.pi / 2. - angle_to_normal
In particular, I have
point = Vector( (-1.8580, -0.9115, 3.6539) )
camera.location = (0.104775, -2.752501, 1.390733)
camera.rotation_euler = Euler( (1.5293482542037964, -0.022381655871868134, -0.09930113703012466), 'XYZ' )
yields pitch=42.5164 degrees
.
I tested whether this is correct by creating an empty
at the location of point
, and varying the camera
's field of view until the empty
is in frame. Since the empty
is not in frame when the camera
's FOV is 96 degrees (> 42.5 * 2), I know the true pitch must be larger than the one I calculated.
My question is, what is the correct way to calcualate the pitch of a point relative to the plane of rotation defined by the camera's Y
axis. Bonus points if you explain where I went wrong :)
Version info:
Blender 2.78 (sub 0)
build hash: 0b13b7a
--------UPDATE---------------
Problem solved. I didn't consider that the elevation of a point from the camera's plane of rotation is constant, but that the apparent pitch will vary as the camera rotates. In my case, the FOV can shrink as the camera approaches the point, and must grow as it rotates away. This is a 'duh' thing, but that's what I forgot about. So my testing procedure was the problem :o
Both the suggested method, the initial method, and a myriad of other ways work - so I've accepted the proposed answer. Thanks for your help!