how to get screen pixel (xy) coordinate of a world object (xyz)?

23 views
Skip to first unread message

Horst JENS

unread,
Oct 9, 2024, 7:59:08 AM10/9/24
to VPython-users
I need to calculate the exact screen coordinate (xy) of an 3d object (xyz). I need the distance from the center of the screen.

my camera axis always is vector(0,0,-1)

I understand that I can calculate
scene.pixel_to_world to get how many world units is one pixel at the xy-plane (going through the origin) has 
and i understand that i can calculate 1/scene.pixel_to_world to get how many pixel a world unit has in the same plane.

However i struggle to determine the distance in pixel from the screen center of any 3d objects with an x,y,z coordinate (with an z coordinate that is other than zero)

Is it possible to use the vector projection to project the position of the 3d object on the screen plane ?

Bruce Sherwood

unread,
Oct 9, 2024, 4:22:18 PM10/9/24
to VPython-users
Not sure this is relevant, but you could set scene.fov to a very small number such as 0.001.

And of course if ;your objects are boxes, you could make their thicknesses very small.

Basically, though, there is no way around the fact that VPython is all about 3D.

Bruce

Bruce Sherwood

unread,
Oct 9, 2024, 4:24:36 PM10/9/24
to VPython-users
I should add that you could restrict your objects to triangles or quads, since these are truly 2D.

Horst JENS

unread,
Oct 10, 2024, 7:55:23 AM10/10/24
to VPython-users
I do have 3d objects (cylinders etc.) and need to determine the pixel (xy) coordinate (x and y distance from the screen center)  of a given 3d object / 3d vector with an x,y,z coordinate. 

Bruce Sherwood

unread,
Oct 10, 2024, 1:03:56 PM10/10/24
to VPython-users
Note too that scene.width is the number of pixels in the width of the canvas and scene.height is the number of pixels in the height of the canvas.

I don't really understand what the problem is. Maybe you need to use some application other than VPython.

Bruce

Reply all
Reply to author
Forward
0 new messages