objective c - Working with circle radials. Subtraction and addition -


i'm working magnetic headings , struggling little bit math around it. let's have heading of 270 degrees, , turn clockwise 110 degrees. want new heading, 020 degrees, output , not 380 degrees. best way this:

if (x > 360) { x = x - 360; }

or can use calculations m_pi make more correct?

thanks replies!

an angle of x degree equal angle x satisfies x = x [360] that's modular arithmetic note x can less -360 or greater 720, in case, adding or subtracting 360 won't give result you're expecting. if want pure calculation method adding or subtracting, can use piece of code:

if (x >= 360){    while( x >= 360)      x -= 360;    } }else if (x < 0){    while( x < 0)      x += 360;    } } 

or, more easily, in objective-c, operator gives value of x satisfying equation below , being in interval of [0;360[,is % operator. can use way:

x = x % 360 

although, angles may not int types. operator won't work because takes int arguments. in case, can use fmod or fmodf functions. syntax use :

x = fmodf(x,360) 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -