|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#31
|
||||
|
||||
|
Re: remainder function
Quote:
Notice the very slight difference between the glibc and Java definitions (handling of divide-by-zero). Last edited by Ether : 02-02-2013 at 11:26. Reason: fixed Java link |
|
#32
|
||||
|
||||
|
Re: remainder function
The "java" link you posted was to gnu libc...
|
|
#33
|
||||
|
||||
|
Re: remainder function
Fixed. Take a look.
|
|
#34
|
||||
|
||||
|
Re: remainder function
Quote:
|
|
#35
|
||||||
|
||||||
|
Re: remainder function
Quote:
Code:
x: 179.0 rem y: 360 result: 179.0 x: 180.0 rem y: 360 result: 180.0 x: 181.0 rem y: 360 result: -179.0 x: 359.0 rem y: 360 result: -1.0 x: 721.0 rem y: 360 result: 1.0 x: -1.0 rem y: 360 result: -1.0 x: -179.0 rem y: 360 result: -179.0 x: -180.0 rem y: 360 result: -180.0 x: -359.0 rem y: 360 result: 1.0 x: -361.0 rem y: 360 result: -1.0 x: -721.0 rem y: 360 result: -1.0 |
|
#36
|
||||
|
||||
|
Re: remainder function
Quote:
For those of you reading this thread for the first time, Math.IEEEremainder(angle,360.0) can be used to convert any angle (in degrees) to the range -180 to 180. This can be very useful when working with the gyro. Let's say you want to find the shortest angular error between your joystick direction angle and the gyro angle. This can be accomplished in one clean line of code as follows: angle_error = Math.IEEEremainder(joystick-gyro,360.0); There's no need for conditional logic. It cleanly handles all input angle ranges for joystick and gyro, including angles greater than 360 degrees and less than -360 degrees. The above assumes that gyro and joystick share the same zero and measurement direction. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|