Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>To Normalised to [0,360):</h3> <p>(I.e. a half open range)</p> <p>Use the modulus operator to perform "get division remainder":</p> <pre><code>361 % 360 </code></pre> <p>will be 1.</p> <p>In C/C++/... style languages this would be</p> <pre><code>gundeg %= 360 </code></pre> <p>Note (thanks to a comment): if gundeg is a floating point type you will need to either use a library function, in C/C++: fmod, or do it yourself (.NET):</p> <pre><code>double FMod(double a, double b) { return a - Math.floor(a / b) * b; } </code></pre> <h3>Which Way To Turn?</h3> <p>Which ever way is shorter (and if turn is 180°, then the answer is arbitrary), in C#, and assuming direction is measured anti-clockwise</p> <pre><code>TurnDirection WhichWayToTurn(double currentDirection, double targetDirection) { Debug.Assert(currentDirection &gt;= 0.0 &amp;&amp; currentDirection &lt; 360.0 &amp;&amp; targetDirection &gt;= 0.0 &amp;&amp; targetDirection &lt; 360.0); var diff = targetDirection - currentDirection ; if (Math.Abs(diff) &lt;= FloatEpsilon) { return TurnDirection.None; } else if (diff &gt; 0.0) { return TurnDirection.AntiClockwise; } else { return TurnDirection.Clockwise; } } </code></pre> <p><strong>NB.</strong> This requires testing.</p> <p>Note use of assert to confirm pre-condition of normalised angles, and I use an assert because this is an internal function that should not be receiving unverified data. If this were a generally reusable function the argument check should throw an exception or return an error (depending on language).</p> <p>Also note. to work out things like this there is nothing better than a pencil and paper (my initial version was wrong because I was mixing up using (-180,180] and [0,360).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload