Easy way to get pixel coordinates?

Hi all,

I got a bit stuck with coordinate transformations and projection method - maybe someone can quickly help me:

With a given view (-vta -vh 180 -vv 180 -vd dx dy dz -vu ux uy uz ), how can I easily (and fast=analytically) determine the pixel coordinates for a direction ax ay az (resolution of the image also given) ? This direction vector is not necessarily a direction used for the pixels (so grepping vwrays output is not an option, would be anyhow too slow). In other words, if I send out a ray with a certain direction, how can I get the pixel coordinates x,y for this direction?



Hi Jan,

The viewloc() routine in ray/src/common/image.c handles this calculation. Normally, you give it a world position (x,y,z) as an FVECT and it computes the image position using a particular view in normalized coordinates plus depth. If you don’t care about depth, just take your direction vector and add it to the view origin (-vp) to compute the world position you give to the routine. If the direction/position is within the view, viewloc() will return VL_GOOD.

Hi Greg,
Thank you for that quick answer - I think that solved it !
I looked in that routine and I understand it as follows:
v_d: viewing direction of image
v_ray: ray direction

h_vec= v_d x v_u
v_vec= h_vec x v_d
d: is the angle (in degree) between v_ray and v_d
then (for a 180°x180° image, no offsets):
x= 0.5 + cos (between v_ray and h_vec) * d/180
y= 0.5 + cos (between v_ray and v_vec) *d/180

x,y is the relative image size


Checking my code, it looks like d in your formula should be the angle between v_ray and v_d divided by the sine of that same angle. (See the sqrt() in the denominator on line 296 of image.c.)