# Figure out width of an entity of which is based upon distance, with two data points given.

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?

-

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.

-
Thank you, this is exactly what I needed. I'm assuming if I say it needs to be 400 wide at 970, I can just add 50 to both 290 in the equation? –  Cow King Apr 18 '12 at 7:49
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. –  Wonder Apr 18 '12 at 7:55