Forums > MaxMSP

line for circular (360°) pots/dials

January 17, 2011 | 5:00 pm

hi

i am stuck with a stupid problem – I am sure the answer is obvious, but just escapes me:

_I use a dial, set to 360° and 360 steps to control my spatialisation – all around, in circles, or wherever in a circular space (the result, scales as 0.-1. goes into GMEM’s Multiouts~ object.
_Now I want to use a line on the control, so i could klik somewhere and the sound slowly goes there
_as long as it has to go on the "normal" way (which is by the "top" of the dial, meaning for exemple from 232 to 103), all is fine and easy
_but if I am at 350, and want to go to 5, i want to take the shortest route………. how to do it (so that in this exemple it would go 351 352 353…… 0 1 2 3 4 5)

many thanks for an idea…..

kasper


January 17, 2011 | 6:01 pm

Just having coffee, let’s see if my brain works. You need to figure out if the clockwise or anitclockwise direction is shorter, given a startAngle and a finishAngle.

if (startAngle > finishAngle), check these two cases: (startAngle-finishAngle) and ((finishAngle+360)-startAngle). Take the smaller direction.

if (finishAngle < startAngle), check (finishAngle - startAngle) and ((startAngle+360)-finishAngle).

I know I’ve done this in a patch somewhere, and I think it might be possible to reduce this equation somewhat. But if you get all four of the comparisons and take the smallest positive one, you’ll be set.

mz


January 18, 2011 | 9:05 am

thanks

finding which way to go (up or down) is I think simple – finding the difference between the 2 positions and checking if its absolute value is > or < to 180 should do ( > means you should go by "the bottom" – 360 being at the bottom)

_What I am looking for is a sort of line which would go from say 355 to 5 in steps of 356 357 358 359 360 1 2 3 4 5, or in other words, which know 1 is the value after 360, and 360 follows 1 in the other way……

many thanks

kasper


January 18, 2011 | 9:22 am

"which is the shortest way" is a real brainfuck, and i really needed to get my
morning coffee first:

1. when next value is smaller than current, then add 360 to next value,

2. now you can compare the difference between increasing and decreasing
(or just check if increasing is smaller or greater than 180 like you wrote above.)

about a line which goes in steps … i would use [metro] and [counter].

since [line] is high priority, too, using metro is not using more CPU but requires
less thinking.

-110


January 18, 2011 | 9:37 am

I think you can find what you want in my patch here :

– Pasted Max Patch, click to expand. –

Cheers

Mathieu


January 18, 2011 | 1:59 pm

Hi Kasper,

this is probably not the most efficient solution, but it works :
convert the value to cartesian coordinates, apply ramp on x y, then back to polar world :

– Pasted Max Patch, click to expand. –

Mathieu


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