The relationship between the 2d projection and a 3d point when using 1 point perspective

projection

I understand the concept of $1$ point projection:

As a $3d$ point gets closer to the vanishing point (further on the $z$ axis), the x and y values of the corresponding $2d$ screen point get closer to the $x,y$ of the vanishing point.

I just don't know what this relationship is.

I assume it will include a $y = m/x$ relationship as the z position will never reach the z value of the vanishing point (infinity).
How I think it will work

In the image I have a diagonal line from the projected point to the vanishing point labled d, for distance, and I think $d = 1/z$ (or some other constant in place of $1$). However, I don't know how I would calculate the values for $ScreenX$, and $ScreenY$.

Please don't give answers only in matrix form as I intend to use them in some code I am writing, and I'm not yet confident enough to turn matrices into single equations.

Edit: I think my question is asking the same as: One-point perspective formula and https://stackoverflow.com/questions/56559793/one-point-perspective-and-point-with-negative-depth

Best Answer

I was talking about this with some people on Discord and one gave me this answer: (I got permission to post it here)

the correct function is: f(x,y,z) = (x/z, y/z)

then z is the depth in the scene and you can move back and forward with f(x,y,z,t) = (x/(z-t), y/(z-t)) where t is the camera z position

generally, if you have a camera transformation, you apply that before the projection transformation

f(x-a,y-b,z-c) = ((x-a)/(z-c),(y-b)/(z-c)) to translate the camera so that (a,b,c) is the origin

later you might want to apply scaling or rotation to the camera. but notice that you subtract rather than add to translate the camera. the same rule applies to scaling and rotation. generally you transform by the inverse of the camera matrix before you project

Related Question