 # Thread: Math: how combine the Z with X and Y?

1. ## Math: how combine the Z with X and Y?

ok. we have a dot X,Y: 10,20.
the screen uses X and Y.
maybe the Z it's just like the zoom.. i don't know.
but how can i combine the Z with X and Y?
i can read several books, but if i don't understand these, i can't continue   Reply With Quote

2. ## Re: Math: how combine the Z with X and Y?

I have no idea what you're actually asking. Are you asking what type you use to represent a point in 3D space? You need top provide much more context for the problem.  Reply With Quote

3. ## Re: Math: how combine the Z with X and Y?

"Are you asking what type you use to represent a point in 3D space?"
yes, but using math. i think you call it Fake 3D  Reply With Quote

4. ## Re: Math: how combine the Z with X and Y?

The math behind it is simple. You start off with 3D Local Coordinates which are the vertices of your polygons but in your case its a dot. But you are going to need more than just that because you also need the Local Coordinates to turn into Camera Coordinates, the Camera Coordinates to turn into Perspective Coordinates (which is where the Z Coord comes into play for the X and Y), and the Perspective Coordinates to turn into Screen Coordinates. You will also need a Viewplane Width, an FOV (Field of View, usually 45 degrees), as well as the Screenwidth and Screenheight.

So now you know that, lets do some math:

Code:
```'This assumes camera position is greater than zero

cameraCoordinates(i).x = vertexList(i).x + cameraPosition.x
cameraCoordinates(i).y = vertexList(i).y + cameraPosition.y
cameraCoordinates(i).z = vertexList(i).z + cameraPosition.z

fov = 45
aspectRatio = 16 / 9
viewPlaneWidth = 2
distance = 0.5 * viewPlaneWidth * tan(pi * (FOV / 2) / 180)
perspectiveCoordinates(i).x = distance * cameraCoordinates(i).x / cameraCoordinates(i).z
perspectiveCoordinates(i).y = distance * aspectRatio * cameraCoordinates(i).y / cameraCoordinates(i).z

alpha = screenWidth * 0.5
beta = screenHeight * 0.5
screenCoordinates(i).x = alpha + alpha * perspectiveCoordinates(i).x
screenCoordinates(i).y = beta - beta * perspectiveCoordinates(i).y```
And thats it! You can see it in action in my 3D Engine in Pure VB in my sig.   Reply With Quote

5. ## Re: Math: how combine the Z with X and Y?

Jacob: i'm sorry but what you think about these simple\very simple formula:
ScreenX = ObjectX / ObjectZ
ScreenY = ObjectY / ObjectZ
?????
(yes without zoom and more)  Reply With Quote

6. ## Re: Math: how combine the Z with X and Y?

3d is more than simply dividing x and y by z. Just like reallife, you need a camera to move around, a field of view, and it needs to be converted to screen coordinates. The 3d needs to be projected. What I done is give you the simplest method in doing so.  Reply With Quote

7. ## Re: Math: how combine the Z with X and Y?

thank you so much for all... thank you  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured