How to limit / cap a looping range of numbers?
Hi,
does anyone know how to limit / cap a looping range of numbers in max? I'm trying to limit the incoming values of a reactivision fiducial marker's rotation (that's in radians and goes from 0 to 6.283 when rotating the marker clockwise, and starts a new cycle from 0 again when rotated clockwise beyond the 6.283, and the applies for rotation in other direction, goes from 0 over to 6.283 again when rotated anticlockwise).
I would like to limit the range so, that it would stay at the maximum 6.283 even if you keep rotating the marker further clockwise and at the minimum 0 when you have reached the minimum when rotating anticlockwise.
Thanks.
uh, i had to read this three times to notice that it is not as straightforward as i first thought.
if delta is bigger than e.g. 1. (about 15% rotation, which is what happens on the transition points) substract 1 from accumulated number of offset rotations, when delta is smaller than -1. (which is what happens at every 2pi to zero transition) then add "1" to the number of offset rotations.
only when the offset is 0 (knob not yet moved across the border - or moved back from 0 to an offset position) let the values pass. if the offset is positive output 2pi, if it is negative, output 0
change
Yes, the incoming numbers range keep "looping" when you keep turning the knob/buttom/marker (from 6.283 over to 0 and up to 6.283 again)
if you have the TuioClient external and TuioSimulator you can simulate the input (right click draging simulates the rotation).
#P button 713 380 24 0;
#P button 650 532 24 0;
#P button 578 534 24 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 85 289 80 9109513 + 3.141593;
#P newex 669 472 50 9109513 6.283185;
#P newex 679 441 50 9109513 select 1;
#P newex 677 409 80 9109513 > 0;
#P newex 297 471 80 9109513 change 0.;
#P newex 578 472 50 9109513 0.;
#P newex 588 441 50 9109513 select 1;
#P newex 586 409 80 9109513 < 0;
#P flonum 262 512 72 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 711 361 100 9109513 # rotation;
#P toggle 461 417 35 0;
#P comment 386 71 100 9109513 input;
#P newex 289 391 80 9109513 gate;
#P newex 461 371 80 9109513 == 0;
#P button 848 187 38 0;
#P newex 842 152 70 9109513 loadbang;
#P number 636 363 67 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 494 275 48 9109513 t b f;
#P newex 640 293 39 9109513 t 0;
#P newex 494 303 86 9109513 accum 0.;
#P newex 450 230 50 9109513 -1;
#P newex 553 230 50 9109513 1;
#P window setfont "Sans Serif" 12.;
#P newex 12 599 178 9109516 expr (6.28318530718);
#P window setfont "Sans Serif" 9.;
#P newex 450 185 50 9109513 select 1;
#P newex 553 185 50 9109513 select 1;
#P button 674 205 24 0;
#P button 631 205 24 0;
#P newex 553 152 80 9109513 < -1.;
#P newex 450 152 80 9109513 > 1.;
#P newex 562 116 80 9109513 - 0.;
#P newex 661 96 80 9109513 f 0.;
#P newex 562 76 80 9109513 t f f b;
#P newex 18 561 80 9109513 clip 0. 1.;
#P flonum 363 36 90 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 27 65 113 9109513 % 6.283185;
#P flonum 44 40 72 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 856 238 100 9109513 reset;
#P comment 34 92 100 9109513 endless knob;
#P connect 21 0 40 0;
#P connect 32 0 33 0;
#P connect 32 0 38 0;
#P connect 36 0 33 0;
#P connect 36 0 39 0;
#P connect 18 0 24 0;
#P connect 18 0 30 0;
#P connect 18 0 21 0;
#P connect 18 0 34 0;
#P connect 23 0 20 0;
#P connect 23 0 19 0;
#P connect 25 0 33 0;
#P connect 4 0 25 1;
#P connect 4 0 6 0;
#P connect 24 0 25 0;
#P connect 24 0 27 0;
#P connect 19 0 24 0;
#P connect 19 0 18 2;
#P connect 8 0 9 0;
#P connect 8 0 10 0;
#P connect 35 0 36 0;
#P connect 34 0 35 0;
#P connect 33 0 29 0;
#P connect 31 0 32 0;
#P connect 30 0 31 0;
#P connect 2 0 3 0;
#P connect 3 0 4 0;
#P connect 9 0 14 0;
#P connect 14 0 11 0;
#P connect 11 0 17 0;
#P connect 6 0 8 0;
#P connect 10 0 13 0;
#P connect 13 0 12 0;
#P connect 12 0 16 0;
#P connect 16 0 20 0;
#P connect 17 0 20 0;
#P connect 20 0 18 0;
#P connect 20 1 18 1;
#P connect 6 2 7 0;
#P connect 7 0 8 1;
#P connect 6 1 7 1;
#P connect 22 0 19 0;
#P window clipboard copycount 41;
example does not 100% work because of the modulo. it will with your real controller input.
and optimized

#P outlet 202 383 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 335 257 69 9109513 split 0. 0.;
#P newex 394 312 202 9109513 expr ( ($f1<0.)*1 + ($f1>0.)*7.283185 ) -1;
#P newex 202 136 202 9109513 expr -(($f1-$f2)>1.) + (($f1-$f2)<-1.);
#P inlet 121 63 15 0;
#P newex 202 332 80 9109513 change 0.;
#P newex 51 312 80 9109513 gate;
#P newex 202 292 80 9109513 == 0;
#P newex 490 166 70 9109513 loadbang;
#P newex 202 206 61 9109513 t b f;
#P newex 275 186 39 9109513 t b 0;
#P newex 202 237 113 9109513 accum 0.;
#P newex 394 99 80 9109513 f 0.;
#P newex 202 79 80 9109513 t f f b;
#P connect 9 0 7 1;
#P connect 9 0 0 0;
#P connect 2 0 6 0;
#P connect 2 0 12 0;
#P connect 8 0 13 0;
#P connect 11 0 8 0;
#P connect 6 0 7 0;
#P connect 12 1 11 0;
#P connect 10 0 4 0;
#P connect 5 0 3 0;
#P connect 3 0 4 0;
#P connect 3 1 2 2;
#P connect 0 0 10 0;
#P connect 1 0 10 1;
#P connect 7 0 8 0;
#P connect 4 0 2 0;
#P connect 4 1 2 1;
#P connect 0 2 1 0;
#P connect 0 1 1 1;
#P window clipboard copycount 14;
Thanks!
Would it be possible to adjust it, so that once it has reached the maximum (6.283) minimum (0) threshold, no matter how long you keep turning/rotate the knob/object/fiducial, the moment you turn/rotate it the other direction, it carries on from that threshold value. (at the moment, when you turn/rotate it clockwise and reach the max threshold of 6.283 and keep turning/rotating the knob/object/fiducial let's say 180 degrees, then when you start turning/rotating it in the other direction (anticlockwise), the value stays at 6.283 for that 180 degrees and will start decreasing only after that.)
hm, make a parallel branch checking for the sign of the delta (> 0 ?), nd whenever it is different than before, reset the accum (trigger the loadbang object again)
no wait, it is easier.
put a [clip -1 1] behind the accum object.
the value which comes out of the clip now represents not the total offset but only the information if it is inside, below 0 or above 2pi, and any turn in the other direction will end up opening the gate again to pass the controller data.
ok that was wrong too. :)
put a [change 0.] after the first expression! now each transition of either of the two directions is only counted once.
doesnt work. (surprise!)
gotta leave house now.
Hmm, yeah. Still can't get it to work. Any helpers?
It's hard to understand your problem the way it's worded above.
Is this what you need?
Nope, the problem is that the input (that you are simulating with a number box) is looping from 0. to 6.283 when turning/rotating the 'knob'.
Roman's last solution (attached below) works in terms of the upper and lower limits/caps/thresholds but it records the amount of rotation, so that if the maximum is reached but the 'knob' is still rotated further, let's say a full cycle, then when turning/rotating it the other direction (anticlockwise) the value will start to decrease only after you rotate it back the same full cycle.
try this one, I hope it will work in your case:
Yep, that's it. Thanks a lot!