#### Archived

This topic is now archived and is closed to further replies.

# Converting x,y,z coordinates to x,y coordinates

This topic is 6296 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is there a simple mathematical formula that converts x,y,z coordinates to x,y coordinates? I read somewhere that the formula was: X=x/z Y=y/z I tried that, but I didn''t seem to work. I don''t want the code for a whole 3d engine, just that formula. I would be thankfull for any help!

##### Share on other sites
pseudo code for some basic 3d projection...

x = (Xwidth/2) + x*256 / (256 - z);
y = (Yheight/2) + y*256 / (256 - z);

##### Share on other sites
cyer:
I am very curious about your formulas. Well, especially those 256 seems to be a speed-hack.

Well, I use a different formula, that supposes that you have a lefthanded coordinate system, x pointing to the right, y up and z away from you and a screen system that stores x right and y down, and the screen has width Xwidth and height Yheight.
Let me say your x-FOV (field of Vision) is v (in degrees):
X = (Xwidth/2) + x * (tan(v/2)*XWidth/2) / z
Y = (Yheight/2) - y * (tan(v/2)*XWidth/2) / z

where tan(v/2)*XWidth/2 is constant for one frame and should thus be precalculated at frame start (changing v from frame to frame can result in the camera-trick seen in Karpov, and some horror movies).

I am not quite sure whether I got the formula correct, but you may find it out yourself, when drawing it on paper (solve it for 2D (x,z) and (y,z))

1. 1
2. 2
Rutin
25
3. 3
4. 4
JoeJ
18
5. 5
gaxio
11

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002215
×