Jump to content

Help with some math calculations


Shmoopy

Recommended Posts

Hi there, I'm making a slider from scratch , I did everything except getting the right formula for the value that should be calculated depending on the min and max values, let me explain:

 

Lets say that the value is set to be between 100(min value) and 250(max value)

 

min value => 100 255 <= max value

[ =======||======= ]

min pos => [ ] <= max pos

 

What we know : • The current slider position ( || xpos ) which is an integer .

• The min and max values .

• The min ( [ ) and max ( ] ) positions that the slider should not exceed .

What we need : • The current value that should be between 100 and 255 which depends on the current slider position

 

 

 

Its been a while since i studied something related to maths , but i believe that this has to do with either matrices or three equations with one unknown value x that should somehow be merged ?

 

 

 

I only remember this formula , but i used to do it with 2 lines and not 3 ( I don't know what its called in maths) like b*100/a = X

 

a ===> 100

b ===> X

c ===> 255

 

How I'm i supposed to find X ?

Edited by Manfred Von Karma
Link to comment
Share on other sites

universetwisters

If I understand what you're trying to ask, you're trying to figure out what "x' is in the equation 100 + x = 255

 

You find X by taking 255 and subtracting 100 from it to get: 155

 

Thus, 100 + 155 = 255

sTgL5iS.png

Link to comment
Share on other sites

If I understand what you're trying to ask, you're trying to figure out what "x' is in the equation 100 + x = 255

 

You find X by taking 255 and subtracting 100 from it to get: 155

 

Thus, 100 + 155 = 255

No actually i was asking how to find the value of X in an interval of [100,255] , if I do b*100/a = X , I get only the value of X when it is dragged to the right half side of the bar

 

100 X 255

[a ==========||===b]

c

And when i do b*255/c = X i get the value when the slider is dragged to the half left side

 

 

100 X 255

[a ====||=========b]

c

Link to comment
Share on other sites

na89340qv0n34b09q340

In numbers where 0 is the lowest value, you add 0 to your number, so 0 +25 = 25. Here if you were 25 increments down the slider you'd add 100 to that, so the 25th position down the slider would be 125.

maybe looking for something like b = xpos + 100 <= 255

 

e: And then adapt that for calculating movement down the slider.

 

If that helps. :)

Edited by Joe Chip
Link to comment
Share on other sites

In numbers where 0 is the lowest value, you add 0 to your number, so 0 +25 = 25. Here if you were 25 increments down the slider you'd add 100 to that, so the 25th position down the slider would be 125.

 

maybe looking for something like b = xpos + 100 <= 255

 

e: And then adapt that for calculating movement down the slider.

 

If that helps. :)

 

It didn't work , I'll just ditch the slider component and move on , thanks guys , this topic can be locked.

Link to comment
Share on other sites

The only problem with the question is that without min pos and max pos it's impossible to do. If we had those 2 values then it would be a doddle.

Link to comment
Share on other sites

value = min_value + (max_value - min_value) * (pos - min_pos)/(max_pos - min_pos);

 

That's if you're happy with linear mapping.

 

(Edit: I'm not sure if you need this direction or the reverse. But formula works both ways. Just swap "pos" and "value", "max_pos" and "max_value", and "min_pos" and "min_value".)

Prior to filing a bug against any of my code, please consider this response to common concerns.

Link to comment
Share on other sites

value = min_value + (max_value - min_value) * (pos - min_pos)/(max_pos - min_pos);

 

That's if you're happy with linear mapping.

 

(Edit: I'm not sure if you need this direction or the reverse. But formula works both ways. Just swap "pos" and "value", "max_pos" and "max_value", and "min_pos" and "min_value".)

Thank you so much :) !

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.