Yet another blog about WPF, Surface, SL, MVVM, NUI.... - Tag - calculation - 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 ! en Mon, 26 Feb 2024 15:40:43 +0100 Jonathan ANTOINE, All rights reserved http://blogs.law.harvard.edu/tech/rss Dotclear How to scale around a specific point and not the center of the Element - Martin Berger http://blog.lexique-du-net.com/index.php?post/2009/10/11/How-to-scale-around-a-specific-point-and-not-the-center-of-the-Element#c3475 urn:md5:04a3699214e5c1fb97a23dd70599030a Fri, 07 Dec 2012 10:20:03 +0100 Martin Berger <p>Hello,</p> <p>what is this last line supposed to perform?</p> <pre> if (scaleDelta &gt; 1.0) _myObjectToScale.Center += new Vector(newCenterXD, newCenterYD); else _myObjectToScale.Center += new Vector(newCenterXD, newCenterYD);</pre> <p>scaleDelta can be less or greater that 1.0, same code will execute.</p> Calculate 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:3acb23ecf73534a53ce14f51bab20096 Mon, 22 Oct 2012 00:06:35 +0200 AlexL <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:a79c6c1e6fe66c9b485cb1c572e7f01f Fri, 06 Apr 2012 09:02:50 +0200 JonathanANTOINE@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:448db09b9bfe1cf48764bf68f7a0dffe Thu, 12 Jan 2012 13:18:30 +0100 tigrou <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:488f8700ec7634b244e273bddcb68720 Wed, 04 May 2011 04:31:45 +0200 RNH <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:761d4a9cbd304434f048d39277d3ecc5 Thu, 28 Apr 2011 22:09:55 +0200 marco polo <p>try this..</p> <pre> private static double GetPositiveAngle(double radian) { if (radian &lt; 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 &lt; 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:819c641b2fd9fc2efdb134e1a7ed178e Sun, 24 Apr 2011 16:42:33 +0200 AronT <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:09a46b577ff2609834813e3dde8a8605 Fri, 08 Apr 2011 12:09:28 +0200 Alan <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> How to scale around a specific point and not the center of the Element - Jonathan ANTOINE http://blog.lexique-du-net.com/index.php?post/2009/10/11/How-to-scale-around-a-specific-point-and-not-the-center-of-the-Element#c2020 urn:md5:dfdec9d2aceddbf64380ec872efd8b65 Sat, 05 Jun 2010 17:16:00 +0200 Jonathan ANTOINE <p>@<a href="http://blog.lexique-du-net.com/index.php?post/2009/10/11/How-to-scale-around-a-specific-point-and-not-the-center-of-the-Element#c2019" rel="nofollow">Jack A</a>:Hello, You may put the IsHitTestVisible property to false ?</p> How to scale around a specific point and not the center of the Element - Jack A http://blog.lexique-du-net.com/index.php?post/2009/10/11/How-to-scale-around-a-specific-point-and-not-the-center-of-the-Element#c2019 urn:md5:868bcaa646412c5c8f917b7fa492c10a Sat, 05 Jun 2010 14:19:27 +0200 Jack A <p>This is a really great article.</p> <p>I would like to be able to prevent a scatterviewitem from continuing to manipulate after I have removed all contacts from it. In other words I would like to prevent an item from being thrown across the screen, but simply want it to stop at my last point of contact. None of the scatterviewitem methods, properties and events seem to offer this capability. Do you know if this is possible?</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:3e73f1878870dd28bc6665ad0f03a5fa Tue, 27 Apr 2010 15:55:23 +0200 René <p>@Rich</p> <p>350 - 10 = 340 &gt; 180 =&gt; 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:fae8c05345cc4f203bb3d836db7e9403 Mon, 29 Mar 2010 21:02:10 +0200 Rich <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:553186f18830d4f4530b7939ee403da2 Fri, 22 Jan 2010 11:17:52 +0100 Liz <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:faa4599cdc1655d18ed1fc46b21139a3 Sat, 28 Nov 2009 23:49:29 +0100 Jonathan 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:3fe3cd3680c5c9e2ffec29417b68fb64 Sat, 28 Nov 2009 22:40:40 +0100 tk <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:11f448175a1121878726b7c8df165dc9 Sat, 07 Nov 2009 12:43:34 +0100 Aubrey <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&lt;a&lt;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 &gt; 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> [ping] How to scale around a specific point and not the center of the Element - DotNetShoutout http://blog.lexique-du-net.com/index.php?post/2009/10/11/How-to-scale-around-a-specific-point-and-not-the-center-of-the-Element#c429 urn:md5:d78c56a1c8d0572d2b90b453fe640ac2 Sun, 11 Oct 2009 18:37:02 +0200 DotNetShoutout <p><a href="http://dotnetshoutout.com/How-to-scale-around-a-specific-point-and-not-the-center-of-the-Element">How to scale around a specific point and not the center of</a></p> <!-- TB --> <p>Thank you for submitting this cool story - Trackback from DotNetShoutout...</p> [ping] How to scale around a specific point and not the center of the Element - DotNetKicks.com http://blog.lexique-du-net.com/index.php?post/2009/10/11/How-to-scale-around-a-specific-point-and-not-the-center-of-the-Element#c428 urn:md5:a1e44278e41aeefd0dc72824ea31569c Sun, 11 Oct 2009 18:22:13 +0200 DotNetKicks.com <p><a href="http://www.dotnetkicks.com/tipsandtricks/How_to_scale_around_a_specific_point_and_not_the_center_of_the_Element">How to scale around a specific point and not the center of</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 - Peter http://blog.lexique-du-net.com/index.php?post/Calculate-the-real-difference-between-two-angles-keeping-the-sign#c427 urn:md5:bc3ed1c70c6cadede7eceb80d70f8020 Sun, 04 Oct 2009 21:21:30 +0200 Peter <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:d1c53eb714ca6995a250a1617d123fa1 Thu, 18 Jun 2009 17:03:56 +0200 Jonathan ANTOINE <p>@[Dan] : The angles can ve really more than 360&nbsp; 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>