Yet another blog about WPF, Surface, SL, MVVM, NUI.... - Tag - angle - Comments
http://blog.lexique-du-net.com/index.php?
In this blog we talk about WPF, Natural User Interface(NUI), Microsoft Surface, WIndows 7, Multitouch, Touchless, JavaFX, MVVM, patterns, tips, tricks .... and a lot of other things !enTue, 23 Jul 2024 07:59:42 +0200Jonathan ANTOINE, All rights reservedhttp://blogs.law.harvard.edu/tech/rssDotclearCalculate the real difference between two angles, keeping the correct sign - AlexL
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c3473
urn:md5:3acb23ecf73534a53ce14f51bab20096Mon, 22 Oct 2012 00:06:35 +0200AlexL<p>Thanks, this helped me out big time!</p>Calculate the real difference between two angles, keeping the correct sign - JonathanANTOINE@falsemail.com
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c3143
urn:md5:a79c6c1e6fe66c9b485cb1c572e7f01fFri, 06 Apr 2012 09:02:50 +0200JonathanANTOINE@falsemail.com<p>Cool !</p>Calculate the real difference between two angles, keeping the correct sign - tigrou
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c3137
urn:md5:448db09b9bfe1cf48764bf68f7a0dffeThu, 12 Jan 2012 13:18:30 +0100tigrou<p>Perfect ! just what i was looking for. Tested and works successfully !</p>Calculate the real difference between two angles, keeping the correct sign - RNH
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c3004
urn:md5:488f8700ec7634b244e273bddcb68720Wed, 04 May 2011 04:31:45 +0200RNH<p>If you only want to know the absolute difference then you can use<br />
DEL = PI - ABS(PI - ABS(A - B)) in radians.<br />
DEL = 180 - ABS(180- ABS(A - B)) in degrees.</p>Calculate the real difference between two angles, keeping the correct sign - marco polo
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c2986
urn:md5:761d4a9cbd304434f048d39277d3ecc5Thu, 28 Apr 2011 22:09:55 +0200marco polo<p>try this..</p>
<pre> private static double GetPositiveAngle(double radian)
{
if (radian < 0)
radian = (Math.PI * 2) - Math.Abs(radian);
return radian;
}</pre>
<pre> public static double GetAngleDifference(double angle1, double angle2)
{
var rslt1 = GetPositiveAngle(angle1);
var rslt2 = GetPositiveAngle(angle2);
if (rslt2 < rslt1)
rslt2 += 2 * Math.PI;
return rslt2 - rslt1;
}</pre>Calculate the real difference between two angles, keeping the correct sign - AronT
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c2979
urn:md5:819c641b2fd9fc2efdb134e1a7ed178eSun, 24 Apr 2011 16:42:33 +0200AronT<p>A snippet of code taken from my archive in Blitz3D that was used to turn a missile towards the player</p>
<p>It eliminates the need to use mod<br />
Will work with angles of any size<br />
Returns an angle in the range -180 to 180<br />
(<br />
diffangle = (actualangle - destangle) + 180;<br />
diffangle = (diffangle / 360.0)<br />
diffangle = ((diffangle - Floor( diffangle )) * 360.0) - 180;<br />
)<br />
!Notes: The Floor command takes the float number and rounds it down to the nearest whole number!</p>Calculate the real difference between two angles, keeping the correct sign - Alan
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c2891
urn:md5:09a46b577ff2609834813e3dde8a8605Fri, 08 Apr 2011 12:09:28 +0200Alan<p>I use:</p>
<p>differenceAngle = (targetAngle - currentAngle) % 360.</p>
<p>this gives you the angle of the target relative to current angle, and is positive for a clockwise rotation.</p>Calculate the real difference between two angles, keeping the correct sign - René
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c1602
urn:md5:3e73f1878870dd28bc6665ad0f03a5faTue, 27 Apr 2010 15:55:23 +0200René<p>@Rich</p>
<p>350 - 10 = 340 > 180 => 340 - 360 = -20</p>Calculate the real difference between two angles, keeping the correct sign - Rich
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c1418
urn:md5:fae8c05345cc4f203bb3d836db7e9403Mon, 29 Mar 2010 21:02:10 +0200Rich<p>@tk is superior as the sign can interpret the direction of rotation. Jon's method doesn't work in some cases, say 10 degrees to 350 reports 20 degree turn, not -20 degree...</p>Calculate the real difference between two angles, keeping the correct sign - Liz
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c1247
urn:md5:553186f18830d4f4530b7939ee403da2Fri, 22 Jan 2010 11:17:52 +0100Liz<p>@tk : That's so elegant - thank you, just what I needed :o)</p>Calculate the real difference between two angles, keeping the correct sign - Jonathan ANTOINE
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c775
urn:md5:faa4599cdc1655d18ed1fc46b21139a3Sat, 28 Nov 2009 23:49:29 +0100Jonathan ANTOINE<p>@<a href="http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c774" rel="nofollow">tk</a> :I simply do it to have the right result : the angle can be more than 360° (suppose you have done 2 turns)....</p>
<p>Your solution may works too... </p>Calculate the real difference between two angles, keeping the correct sign - tk
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c774
urn:md5:3fe3cd3680c5c9e2ffec29417b68fb64Sat, 28 Nov 2009 22:40:40 +0100tk<p>I was wondering two things: why do you use while instead of if, is that C#? and, perhaps, could you do<br />
double difference = mod( secondAngle - firstAngle + 180, 360 ) - 180;<br />
I suppose it depends on the compiler or deeper knowledge of the computer to know which is faster.</p>Calculate the real difference between two angles, keeping the correct sign - Aubrey
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c659
urn:md5:11f448175a1121878726b7c8df165dc9Sat, 07 Nov 2009 12:43:34 +0100Aubrey<p>Yep. We use this where I work (and in my homebrew). We call it "Normalize180", and there's a variant called "Normalize360", which does the same thing, but in the range 0f<a<360f.</p>
<p>You could also divide the difference by 180.0f, then take only the fractional part of that (behind the '.' ) and multiply it by 180, making sure to maintain the sign.</p>
<p>i.e.<br />
float NormalizedAngle = diff / 180.0f;<br />
if(diff > 0){<br />
return (NormalizedAngle - Math.Floor(NormalizedAngle)) * 180.0f;<br />
} else {<br />
return (( NormalizedAngle - ( Math.Floor(NormalizedAngle) + 1.0f ) * 180.0f );//Errr... not sure about this bit - have to deal with negative case. Might be a better way to get the fractional part than number minus floor(number)<br />
}</p>
<p>That would probably be less cycles than a while loop, but typical input numbers are unlikely to be high, so your approach is probably fine in most cases.</p>Calculate the real difference between two angles, keeping the correct sign - Peter
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c427
urn:md5:bc3ed1c70c6cadede7eceb80d70f8020Sun, 04 Oct 2009 21:21:30 +0200Peter<p>You saved my day <img src="themes/default/smilies/wink.png" alt=";-)" class="smiley" /></p>Calculate the real difference between two angles, keeping the correct sign - Jonathan ANTOINE
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c235
urn:md5:d1c53eb714ca6995a250a1617d123fa1Thu, 18 Jun 2009 17:03:56 +0200Jonathan ANTOINE<p>@[Dan] : The angles can ve really more than 360 and it will then works with this code.<br />Also I don't think using a while instead of an if cause a lot of perf problems...</p>
<p>++</p>Calculate the real difference between two angles, keeping the correct sign - Dan
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c234
urn:md5:f6cb3a0fc05fa6cdc62a0a472a4774a4Thu, 18 Jun 2009 16:59:09 +0200Dan<p>Wouldn't if statements make more sense than while loops?<br />
Thanks for the tip.</p>[ping] Calculate the real difference between two angles, keeping the correct sign - DotNetShoutout
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c114
urn:md5:3283898832df1afcfc502bf828c9bddeMon, 20 Apr 2009 13:11:52 +0200DotNetShoutout<p><a href="http://dotnetshoutout.com/Calculate-the-real-difference-between-two-angles-keeping-the-correct-sign">Calculate the real difference between two angles, keeping</a></p>
<!-- TB -->
<p>Thank you for submitting this cool story - Trackback from DotNetShoutout...</p>[ping] Calculate the real difference between two angles, keeping the correct sign - DotNetKicks.com
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c113
urn:md5:fd86812553db3f1e80d62aef3d75b202Mon, 20 Apr 2009 13:00:18 +0200DotNetKicks.com<p><a href="http://www.dotnetkicks.com/tipsandtricks/Calculate_the_real_difference_between_two_angles_keeping_the_correct">Calculate the real difference between two angles, keeping</a></p>
<!-- TB -->
<p>You've been kicked (a good thing) - Trackback from DotNetKicks.com...</p>Calculate the real difference between two angles, keeping the correct sign - Jonathan ANTOINE
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c101
urn:md5:0a663c463c5605e411fe842cbb2966e1Wed, 08 Apr 2009 17:31:16 +0200Jonathan ANTOINE<p>@<a href="http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c99" rel="nofollow">LEM</a> : You are welcome !</p>Calculate the real difference between two angles, keeping the correct sign - LEM
http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c99
urn:md5:bdfcf6e7469baf3d770f40013c9079baWed, 08 Apr 2009 16:48:58 +0200LEM<p>Thanks. it was very useful.</p>