Mathematics Help Needed!

Updated on October 18, 2017 in [A] Other Answers
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on October 17, 2017

Hey everyone!

I’m stuck trying to develop a simple algorythm, since I’m not really good at maths.. I’ll try to explain the best I can my issue:

I have a variable X, and its value goes from a minimum of A, to a maximum of B, where A and B are values between 0.0f and 1.0f, and B is always greater than A. all these values, X, A and B are already set up in my equation, the new value I need to calculate is a percentage, let’s say a Y variable between 0f and 1f, wich represents the “proximity” of X towards the A value (or the B value, it doesn’t matter), this means that if X is equal to A, Y will be equal to 0, if X ==B Y will be 1f, and if X is half way between A and B, Y will be 0.5f.

 

I REALLY bad at algorythms, so can anyone help me out here!?

THANK YOU!!

  • Liked by
Reply
0 on October 17, 2017

I think…

Y = (X-A) / (B-A)

B – A is the total distance between A and B, X – A is the amount of distance away from A, so Y should equal the percent.

Should work for any values as long as A < X < B

 

  • Liked by
Reply
Cancel
0 on October 18, 2017

wow it was simplier that I thought, at a first flance that should do the job! I’ll test it out, thank you!

  • Liked by
Reply
Cancel