Create a curved line. I'm bad at math.

dftm's icon

Hi everyone,

I've got a question.
I'm receiving a range of numbers from a sensor via an arduino. The range is 0-1023.
512 will be the center point. When it moves from center to min or max, it has to do this exponentially.
My question: what line function do I need to use. My math ain't that great.

I hope some one will understand my question (don't really know how to explain better),
so I've added a picture to help you understand my question. (it's line1.jpg, ignore the other one)

3025.lijn1.jpg
jpg
Sergio Martins's icon

I'm bad at math too and max think about us :) check the curve~ object...it outputs signal so not sure if it is what you want...

cheers

brendan mccloskey's icon

Hi
the most basic curve can be generated thus: input integer --> [pack i 100] --> [line] --> curve output; however, the fifth argument to [scale] provides for exponential mapping:

Max Patch
Copy patch and select New From Clipboard in Max.

And Sergio is right to suggest [curve~], but it will only create nice curves if the input is linear.

Check out the helpfiles for [expr], [function], [itable] and [multislider], they are also often used to remap input values in this way.

Brendan

Rob Ramirez's icon

also take a look at the jit.path object, which will allow you to edit the curve using handles, as well as easily visualize the curve in opengl.

Max Patch
Copy patch and select New From Clipboard in Max.

below is a patch and screenshot.
i scaled the range by 1000 for easier opengl visualization.

3031.Screenshot20111205at12.30.02PM.png
png
Roman Thilenius's icon

you can get that into one line of code like in my recent post here:

the abstarction is also somewhere here in the forums.

but i would suggest that you find your own was by breaking the
problem down into smaller tasks:

1. split the range into three ranges of 0-511, 512, and 513-1023
2. reverse the direction of the lower part
3. perform the desired distortion with log, exp or whatever you wish while keeping the input range.
4. reverse the 511-0 back to 0-511
5. mix the thre rages back to one ...

-110