Help with the math on this?

Started by
23 comments, last by Ectara 9 years, 9 months ago

Well yeah, I assumed he wanted linear interpolation not polynomial.

Lagrange's Polynomial Interpolation Formulae will do that though. EDIT: Maybe Legendre not Lagrange ;)

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
Advertisement

thanks for all the help guys!!!

(imo) this is not interpolation, this is some specyfic case of linear transformation ( [0,1] -> [0,1] ) whose probably has some naming, though i dont know it

Stop overly complicating it guys.

float getVal(float in)

{

return in==1.0f ? 0.0f : in==0.0f ? 1.0f : in==0.1f ? 0.9f : in==0.9f ? : 0.1f; --assumes infinite precision floating point, otherwise not possible to satisfy requirements

}

o3o

I'm pretty sure that's not what the op wants, I expect they want 0.5 to map to 0.5 and 0.25 to map to 0.75, so f(t) = 1 - t is correct.
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

I don't understand why some of you developers are so against 'generalisations', that is what you do all the time anyway. Instead of bashing the people who mentioned LERP and made it more 'complicated', you should be grateful to learn something new, although more 'complicated'. It is a good exercise to get better at what you are doing. If you are ever going to translate between any other values, that is the formula you will need to to get the job done anyway. It is seriously good to know, although it shouldn't be too hard to come up with that yourself with a bit of thinking.

It is not like the easy solution was not posted already.

Personally, I have used both LERP and 1-t a lot of times without even seeing the connection, so for me it was kind of useful. I have actually 'invented' LERP a lot of times in my head already without even knowing the 'label' LERP. I am sure anyone who has ever needed a fixed number of steps between two arbitrary points have done that.

By the way... Using values between 0 and 1 is used in a lot of fields, one which is probability. Me, for one, last time I used this kind of value was to multiply with sample data to make a volume control, (0 = 0, 1000000 = 1) so these kind of values crops up everywhere.

I don't understand why some of you developers are so against 'generalisations', that is what you do all the time anyway.

I don't think anyone's against generalizing, per se. Personally, I feel that over-complicating the situation is adding nothing significant; otherwise, we could provide all sorts of methods to solve simple problems, like trying to tell our children to find the area of a square for their geometry homework by integrating.

However, there's something more to it:

I want to take the value

It sure sounds like he's not doing it out of curiosity, by his wording. It also sounds like he wants to program something to do it; otherwise, why ask, if he could do it by hand, and isn't asking simply to be scholarly?

The thing is, if he doesn't understand the algorithm for what he wants, and he's trying to implement it, then giving him a complex and inefficient way of solving the problem isn't the best answer, if he may be unable to derive the simpler answer for his use case. Linear interpolation is much slower than subtracting two numbers, so it is no better of an answer than the one already posted.

Of course, if Paradigm Shifter was attempting to build on fir's answer with more information for the sake of knowledge, then that's well and fine. However, providing a one line answer that may sound contradictory to someone who doesn't immediately see the link between the two creates confusion. If Paradigm Shifter's first two posts were combined into one, from the beginning, and underscored that the simplification was what the OP was after, and how we got there, there probably would have been less conflict.

All in all, with clarification in place, I agree with the above points.

I am astounded at how many replies there are to this question

I gave a one line answer because the OP asked what it was called, fir had already given the specific answer and I just said what the technique was called in the general case ;)

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

I am not sure how to go about setting up a method to determine a color value for each object that is unique. Obviously they need to be unique to determine which one you clicked on, but with only RGB 256 each channel just doing red++ for 256 values and moving to green++ is one way but how can I code it so it a rolling increment.

e.g.

start with red = 0, red++ when red hits 255 move to green, when green hits 255, blue is incremented to 255 then after that start with red = 1, green = 1, blue = 1 or other combos green = 1, blue = 1 red = 0?

Not sure I am making myself clear, but starting to think ray casting and AABB would just be easier in the long run?

THanks!

This topic is closed to new replies.

Advertisement