Convert angle range from -180 180 to 0 360?

Sep 11, 2012 at 10:19am

Convert angle range from -180 180 to 0 360?

Hi all,

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…
Any pointers?

#64321
Sep 11, 2012 at 10:42am

not sure if i get it – but how about addition? + 180?

:?

#231942
Sep 11, 2012 at 10:54am

scale object

“scale -180 180 0 360″

#231943
Sep 11, 2012 at 11:20am

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

#231944
Sep 11, 2012 at 1:04pm

try [expr ($i1+360)%360]

mathieu

#231945
Sep 11, 2012 at 5:27pm

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.

#231946
Sep 12, 2012 at 1:12pm

Thanks Mathieu; that works like a charm!

#231947

You must be logged in to reply to this topic.