2
$\begingroup$

I'm trying to figure out this problem for game development. I don't have that great of mathematics education and stumped for a formula for this. Please fix my tags if they don't make sense.

I know that I need an entity to be 60 units wide at 8,000 distance.

I also know that I need an entity to be 350 units wide at 970 distance.

What formula should I use to calculate the width of the entity given any distance?

2 Answers 2

3

Assuming that you want a linear fit, suppose you want width at distance x to be ax + b. Then 800a + b = 60, and 970a + b = 350.

You can solve this to get width at distance x to be $60 + \frac{290 \times 8000}{7030} - \frac{290}{7030}x$ which is roughly $390.014225 - 0.0412517781x$. This will make your entity disappear at about 9454 distance, but from the question it looks like its distance will not exceed 8000 units hopefully.

  • 1
    If you want it to be a1 wide at b1 and a2 wide at b2, the formula is $a1 + \frac{(a2-a1)*b1}{b1-b2} - \frac{a2-a1}{b1-b2}x$. You can plug in the values as you want.2012-04-18
1

This 350 does not compute. If an object appears 60 wide at 8000 distance, then at 970 distance, it is about 8.25 times closer, and should be that many times bigger: 60 x 8.25 = 495.

(If this is not about perspective, then what?)

  • 0
    This is probably correct, the two data points I gave were just eye balling it. I'm going to have to tweak the values later on and make it accurate like you pointed out. I'm overlaying targeting reticules in a 2D space after projecting them into the 3D world.2012-04-18