How can I show a 3d point on a 2d screen (picturebox)?
Given the following...
* The 'camera' position as (X,Y,Z)
* The direction that the camera is pointing in, as heading (from 0 degrees) and elevation (upwards is 0 degrees)
* The 3d coordinates of the point in question as (X,Y,Z)
I've been busting my ass for days over the trigonometry but I can't get it working...
VB Code:
Public Function Translate3D2D(ByVal X As Single, ByVal Y As Single, ByVal Z As Single) As POINTAPI
'POINTAPI is just a UDT with X and Y (both single) members
Dim Ret As POINTAPI
Dim dx As Single, dy As Single, dz As Single
Dim Ax As Single, Ay As Single, Dist As Single
dx = X - mcamCamera.X
dy = Y - mcamCamera.Y
dz = Z - mcamCamera.Z
'Ax is the horizontal angle between the cam heading and the point
This I've found browsing through my old notes. I remember it used to work but haven't tried it recently.
(Refer to the drawing):
R: distance from origin O to origin sO
D: distance from origin sO to observer
Theta: azimuthal angle
Phi: polar angle
(x, y, z): 3D coordinates of a point that we want to represent in 2D
(cx, cy): coordinates of origin sO relative to the screen's lower left corner
(sx, sy): the sought 2D coordinates
Let,
xe = -x sin(Phi) + y cos(Phi)
ye = -x cos(Phi) cos(Theta) - y sin(Phi) cos(Theta) + z sin(Theta)
ze = -x cos(Phi) sin(Theta) - y sin(Phi) sin(Theta) - z cos(Theta) + R + D
Then:
sx = cx + D * xe / ze
sy = cy + D * ye / ze
Last edited by krtxmrtz; Aug 22nd, 2003 at 10:13 AM.