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:
  1. Public Function Translate3D2D(ByVal X As Single, ByVal Y As Single, ByVal Z As Single) As POINTAPI
  2.  
  3. 'POINTAPI is just a UDT with X and Y (both single) members
  4.  
  5. Dim Ret As POINTAPI
  6. Dim dx As Single, dy As Single, dz As Single
  7. Dim Ax As Single, Ay As Single, Dist As Single
  8.  
  9. dx = X - mcamCamera.X
  10. dy = Y - mcamCamera.Y
  11. dz = Z - mcamCamera.Z
  12.  
  13. 'Ax is the horizontal angle between the cam heading and the point
  14. Ax = mcamCamera.Heading - (Atn(dx / dz) + 180) 'probably wrong
  15.  
  16. 'dist is the horizontal distance (xy plane)
  17. Dist = Sqr((dx * dx) + (dy * dy))
  18. 'Ay is the vertical angle between the cam elevation and the point
  19. Ay = mcamCamera.Elev - Atn(dy / Dist) 'probably wrong
  20.  
  21. 'convert these angles into screen coordinates
  22. Ret.X = (mcamCamera.ZDist * Tan(Ax))'probably wrong
  23. Ret.Y = (mcamCamera.ZDist * Tan(Ay))'probably wrong
  24.  
  25. Translate3D2D = Ret 'pass results back to the calling procedure
  26.  
  27. End Function

Where am I going wrong?

Please help.

Regards, Adam