Can't understand cube projection algorithm. (Python)

117 Views Asked by At

I've been exploring a Python code that generates a rotating 3D cube animation using ASCII characters in a terminal window. The code employs a projection algorithm to project the cube's 3D coordinates onto a 2D screen.

Here's the complete code. and here's the snippet of the relevant code:

# Relevant snippet
proj = [(round(w/2+xm*x/(z+2)), round(h/2+ym*y/(z+2))) for x, y, z in cube]

In this line, the variable proj calculates the projected 2D coordinates of the cube's vertices. However, I'm trying to understand the significance of adding '2' to the 'z' coordinate within the projection equation.

I've observed that altering this value significantly affects the appearance of the cube.

Can someone explain why we are adding '2' and why not any other value?

0

There are 0 best solutions below