0
$\begingroup$

Im a developer that likes maths, but dont have much experience,

I had constructed a graphic that animates a bar that grows on the X axis according to a value.

So, I have the values for the x positions of the bar, and the thresholds for the values,

xPosition  13|----------------|105 [x position to find]  Value       0|----------------|20  [known value] 

so, value = 0 should be showed in xPosition = 13... and value = 20 should be showed in xPosition = 105.

The formula I use for figuring this out:: [92 = 105-13; 20 = 20 - 0]

xPos = [value *  92/20] + 13 

Which is Ok and works properly,

but when I go to other tresholds, i have to use some "magical" values

ie:

xPosition  105|----------------|380 [x position to find]  Value       20|----------------|150  [known value] 

275 = 380-105 ; 130 = 150 -20;; steps

 xPos = [value *  275/130] + 62 

So where does this "62", comes from? [105-20 = 85]

Im doing other graphs with same formula, all works, but i have to use this "magic" number, that i havent understood where it comes from?

Hope i make sense ;) Thanks!

1 Answers 1

1

Linear relationship: from xPosition to value. $62$ comes from $105 - 20 * \frac{380 - 105}{150 - 20} = \frac{815}{13} \approx {62.7} $

enter image description here

thus the formula is that $xPos = [value * \frac{x(a)-x(b)}{a-b}] + c$

c(the magic number) can be calculated by substituting $(value,xPos)$ i.d. $(a,x(a))$.

Sorry for my poor English.

  • 0
    For some basic information about writing math at this site see e.g. [here](http://meta.math.stackexchange.com/questions/5020/), [here](http://meta.stackexchange.com/a/70559/155238), [here](http://meta.math.stackexchange.com/questions/1773/) and [here](http://math.stackexchange.com/editing-help#latex).2012-10-19