How to calculate intermediate point?

351 Views Asked by At

I am developing an Android application, and I am trying to develop a chart with points, but I am struggling with some (probably) basic math.

So, the point is: I am drawing a price chart, and I know that the maximum price, being 50000€ is drawn at the 0px. At the other end, the minimum price, being 20000€ is drawn at the 800px. Now, let's suppose that I got a price between the minimum and maximum like 27500€. How can I calculate the px for that price knowing the information I gave earlier?

If someone could help me with this calculation, or at least point me in the right direction, I would really appreciate it!

2

There are 2 best solutions below

0
On BEST ANSWER

Begin by seeing you have 800 px for $(50,000-20,000) = 30,000 units$ so you have $\frac{800}{30000} \frac {p}{unit}$. Since 50,000 is your zero mark, it simply becomes $px = \frac{800}{30000}*(50,000-Price) $

So for Price = 27500, you have $px = \frac{8}{300}*(50,000-27,500) = 600px$

0
On

In general, let the minimum price be $a$ and the maximum price be $b$. Suppose the minimum price is to be plotted at coordinate $y_a$ and the maximum price plotted at coordinate $y_b$.

So in your case, $a = 20000$, $b = 50000$, $y_a = 800$, and $y_b = 0$.

Then suppose you have a third price, say $c$, satisfying $a < c < b$. In your case, $c = 27500$. You want to find the coordinate $y_c$ such that $c$ is plotted to scale. Then we require $$y_c = \frac{c-a}{b-a} y_b + \frac{b-c}{b-a} y_a.$$ Substituting, you get $y_c = 600$.