This is a follow up to this previous message (see VtkCamera angular ranges ranges? - Support - VTK). Can the vertical and horizontal angles for each pixel on a display be calculated? How?
Thanks for any help.
M.
This is a follow up to this previous message (see VtkCamera angular ranges ranges? - Support - VTK). Can the vertical and horizontal angles for each pixel on a display be calculated? How?
Thanks for any help.
M.
The answer is yes, if you know the viewport size in pixels and the camera’s view angle.
viewport size: w, h
camera view angle: a
also define these:
pixel coords: x,y
pixel angles: theta,phi
Coords can be computed from angles as follows:
x = w/2 + h/2 * tan(theta)/tan(a/2)
y = h/2 + h/2 * tan(phi)/tan(a/2)
And angles from coords as follows:
theta = atan( tan(a/2) * ( 2*x/h - w/h ) )
phi = atan( tan(a/2) * ( 2*y/h - 1 ) )
I can give no guarantees on the correctness, this is just a back-of-the-envelope calculation. But the math is fairly straightforward.
Thanks David!
I am not able to follow your derivation well. I take that theta is the horizontal angle subtended by a pixel and phi the vertical one. Correct? The ‘view angle’ is the vertical angle covered by h pixels?
Do you have a sketch? Sorry for the trouble
Your interpretation of theta, phi, and “view angle” are all correct. I have no figure, but it shouldn’t be hard to picture in your head.
You can derive the relationship from the fact that y
must be a linear function of tan(theta)
, plus the constraints that y=0
when theta=-a/2
and that y=h
when theta=+a/2
.