Forums > MaxMSP

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

December 5, 2011 | 1:00 pm

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)

Attachments:
  1. lijn1.jpg

December 5, 2011 | 2:41 pm

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

s


December 5, 2011 | 3:09 pm

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:

– Pasted Max Patch, click to expand. –

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


December 5, 2011 | 5:38 pm

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.

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

– Pasted Max Patch, click to expand. –

[attachment=178451,3031]

Attachments:
  1. Screenshot20111205at12.30.02PM.png

December 5, 2011 | 9:20 pm

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

http://cycling74.com/forums/topic.php?id=36275

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


Viewing 5 posts - 1 through 5 (of 5 total)