A silly problem which I ran into several times and always worked around but never quite solved.
I have an angle in the range of -180 to 180 and want to convert it to a range from 0 to 360…
not sure if i get it – but how about addition? + 180?
"scale -180 180 0 360"
The number is a rotation, a heading. Say 0 is in ‘front’, -180/180 is in the ‘back’. After the conversion 0/360 should be in ‘front’, 180 in the ‘back’.
While both solutions will give a number between 0 and 360, the ‘front’ will be 180
try [expr ($i1+360)%360]
Assuming your input is always in the range [-180 .. 180], you could do [if $i1 >= 0 then $i1 else out2 $i1] and pass the rightmost outlet through a [+ 360] object. Leftmost of the [if] and the [+ 360] outlet both connect to the further processing.
But there are a gazillion other ways to do this. Some are more robust for input values outside the specified range.
Thanks Mathieu; that works like a charm!
C74 RSS Feed | © Copyright Cycling '74