Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
For some basic information about writing math at this site see e.g. here, here, here and here. –  Rick Decker Oct 19 '12 at 12:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.