Perspective Drawing Height at a Distance

3dcalculustrigonometry

sorry if my formatting is a bit off, this is my first post using MathJax.

I am trying to render a perfectly vertical line in a 3d plane at a 10 meter distance from a camera, and am having trouble using my trig/calc knowledge to solve the diminishing height that can actually be seen for each meter of height added/stacked. In short, how tall will a 10m tall line appear in perspective when it is 10m away from the origin or camera. This is what I have so far:

  1. In a 2D world, I have right triangle. The shape is 10m horizontal from the origin and then vertical rise from the right angle. Both the adjacent (horizontal) line and the opposite (vertical) are in meters, which I used to give me a hypotenuse. The hypotenuse is now the actual distance away the top of each segment of the line is from the viewer or perspective.

$$\sqrt{1(o)^2+10(a)^2} = 10.0499$$
$$\sqrt{2(o)^2+10(a)^2} = 10.1980$$
$$\sqrt{3(o)^2+10(a)^2} = 10.4403$$
$$\sqrt{4(o)^2+10(a)^2} = 10.7703$$
$$\sqrt{5(o)^2+10(a)^2} = 11.1803$$
$$\sqrt{10(o)^2+10(a)^2} = 14.1421$$

  1. I then tried calculating the amount the line would need shrink to accommodate real world 3D perspective. I figured that, as the line is perfectly straight and vertical, it should shrink linearly. But, I could not figure out how to do this. I know that the base line is 10m, and the next hypotenuse us 10.4999m, for a 1 meter tall triangle. I tried reducing the line by the exact percent the hypotenuse changes: $$\frac{1(o)}{1+\frac{10.0499-10}{10}(\Delta{h})}$$ I also tried averaging, as half of the line in views behind the half way point, and half of it is in front of the half way point: $$\frac{1(o)}{1+\frac{\frac{10.0499+10}{2}-10}{10}(average\Delta{h})}$$ But then I got stuck. I though either of these may work, but, as the change in hypotenuse is not linear, it meant that the 1 meter lines were not going to decrease linearly in size.

    As a side note, I will ultimately have precise vanishing point (x, y) locations, but, I feel as though these will only help me once I start troubling my way through 5 point perspectives, and know the exact size of display I will be using, like a camera, eyes, or monitor. I am trying to develop my own 3D game/video rendering engine, but want to figure out the math behind real world perspectives before attempting to code it.

    I have a feeling that there is an actual formula for this out there somewhere, but I have searched and can not find it. When using excel, to 200m in the opposite, I get a curve and can calculate a polynomial trend line that almost fits with 6 orders, but it still does not fit as good as it should. I have also considered limits, but can not seem to remember how they work.

Do you have any suggestions, formulas or links to possible formulas or similar problems to figure out? The example would also work knocking my triangle on its side, still only seeing a line on the horizontal.

Thank you for any help!

Best Answer

As far as I know the height of the line should be inverse proportional to the distance ie. $h\approx 1/d$. Early 3D video games (e.g. Wolfenstein 3D) used this technique called raycasting (related but not to be confused with raytracing) to make a 2D world appear 3D, hence commonly called 2.5D. You may want to consult tutorials on raycasting like this one by Permadi.

Related Question