<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Sorry for my mistake in in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010384#M105809</link>
    <description>&lt;P&gt;Sorry for my mistake in omitting the square root in the final ACOS statement.&lt;BR /&gt;
	Using the square of the modulus ( and not taking the&amp;nbsp; square root) for the tests and&lt;BR /&gt;
	putting the square root in the ACOS argument avoids taking an extra square root earlier, thus saving several machine cycles.&lt;/P&gt;</description>
    <pubDate>Mon, 12 May 2014 07:23:48 GMT</pubDate>
    <dc:creator>Anthony_Richards</dc:creator>
    <dc:date>2014-05-12T07:23:48Z</dc:date>
    <item>
      <title>Numerically stable algorithm for the angle between two vectors</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010374#M105799</link>
      <description>&lt;UL&gt;
	&lt;LI&gt;Is there anyone who knew the numerically stable algorithm for the angle between two vectors?&amp;nbsp;&lt;/LI&gt;
	&lt;LI&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;- atan2 is more stable than acos?&lt;/SPAN&gt;&lt;/LI&gt;
	&lt;LI&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;- acos is more stable than atan2, if the two vectors have normalized?&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 08 May 2014 12:19:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010374#M105799</guid>
      <dc:creator>Mincheol_L_</dc:creator>
      <dc:date>2014-05-08T12:19:06Z</dc:date>
    </item>
    <item>
      <title>Are these 2D or 3D vectors</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010375#M105800</link>
      <description>&lt;P&gt;Are these 2D or 3D vectors and do you want the acute angle? atan2 gives you the answers in the -PI to &amp;nbsp;PI range, acos is 0 to PI and asin is&amp;nbsp;&amp;nbsp;-pi/2 to pi/2 so it depends what you want.&lt;/P&gt;

&lt;P&gt;I don't think you will find any difference in the stability, atan2 is the most versatile and informative. Use real(8) if accuracy beyond 7SF is needed.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;For 3D I normalise the vectors , do an asin of the dot product.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2014 13:20:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010375#M105800</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2014-05-08T13:20:53Z</dc:date>
    </item>
    <item>
      <title>Thanks app4619.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010376#M105801</link>
      <description>&lt;P&gt;Thanks app4619.&lt;BR /&gt;
	I want both acute angle and obtuse angle.&lt;BR /&gt;
	The algorithm have to be different for 2D and 3D vectors?&lt;BR /&gt;
	If so, please give me more detailed information.&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2014 13:44:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010376#M105801</guid>
      <dc:creator>Mincheol_L_</dc:creator>
      <dc:date>2014-05-08T13:44:45Z</dc:date>
    </item>
    <item>
      <title>If the vectors were 2D (a1,a2</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010377#M105802</link>
      <description>&lt;P&gt;If the vectors were 2D (a1,a2) &amp;amp; (b1,b2) &amp;nbsp;the angle would be atan2(b2,b1)-atan2(a2,a1) the angle being positive as the x axis rotates towards the y axis. The only problem case is if either of the vectors is 0,0 which is indeterminate (x,0) and (0,y) are OK.&lt;/P&gt;

&lt;P&gt;for 3D you have acos( dot_product(v1,v2)/(norm2(v1)*norm2(v2))) &amp;nbsp;where v1 and v2 are 3d vectors.This one is always going to give an acute angle and again null vectors will kill it (div zero).&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2014 14:04:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010377#M105802</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2014-05-08T14:04:00Z</dc:date>
    </item>
    <item>
      <title>How about</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010378#M105803</link>
      <description>&lt;P&gt;How about&lt;/P&gt;

&lt;P&gt;eta=+ve number a litle bigger than the inverse of the biggest +ve real number representable by the machine&lt;BR /&gt;
	norm1=x1*x1+y1*y1+z1*z1&lt;BR /&gt;
	if(norm1.lt.eta) ifail=-1, return&lt;BR /&gt;
	norm2=(x2*x2+y2*y2+z2*z2 )*norm1&lt;BR /&gt;
	if(norm2.lt.eta) ifail=-1, return&lt;BR /&gt;
	angle=acos( (x1*x2+y1*y2+z1*z2)/norm2 )&lt;BR /&gt;
	ifail=0, return&lt;/P&gt;

&lt;P&gt;?&lt;/P&gt;

&lt;P&gt;&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2014 16:58:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010378#M105803</guid>
      <dc:creator>Anthony_Richards</dc:creator>
      <dc:date>2014-05-09T16:58:42Z</dc:date>
    </item>
    <item>
      <title> </title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010379#M105804</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Try to scale the numbers such that you do not have overflow/underflow&lt;/P&gt;

&lt;P&gt;HowBig1 = abs(x1) + abs(y1) + abs(z1)&lt;BR /&gt;
	if(HowBig1 .eq. 0.0) HowBig1 = 1.0&lt;BR /&gt;
	HowBig2 = abs(x2) + abs(y2) + abs(z2)&lt;BR /&gt;
	if(HowBig2 .eq. 0.0) HowBig2 = 1.0&lt;BR /&gt;
	x1fixed = x1 / HowBig1&lt;BR /&gt;
	y1fixed = y1 / HowBig1&lt;BR /&gt;
	z1fixed = z1 / HowBig1&lt;BR /&gt;
	... same for the 2's&lt;BR /&gt;
	norm1 = x1fixed**2 + y1fixed**2 + z1fixed**2&lt;BR /&gt;
	norm2 = (x2fixed**2 + y2fixed**2 + z2fixed**2)*norm1&lt;BR /&gt;
	if(norm1.lt.eta) ifail=-1, return&lt;BR /&gt;
	angle=acos( (x1fixed*x2fixed+y1*y2fixed+z1fixed*z2fixed)/norm2 )&lt;BR /&gt;
	&lt;BR /&gt;
	Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2014 17:28:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010379#M105804</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2014-05-09T17:28:59Z</dc:date>
    </item>
    <item>
      <title>Where are the square roots in</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010380#M105805</link>
      <description>&lt;P&gt;Where are the square roots in the norms?&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2014 17:51:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010380#M105805</guid>
      <dc:creator>NotThatItMatters</dc:creator>
      <dc:date>2014-05-09T17:51:28Z</dc:date>
    </item>
    <item>
      <title>That is for you to add. The</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010381#M105806</link>
      <description>&lt;P&gt;That is for you to add. The snip of code provided by Anthony did not include them so I did not wish to clutter my example with additional statements. The intent of the example was to illustrate how to scale the input such that the sum of the squares would not overflow.&lt;/P&gt;

&lt;P&gt;I will point you in the direction, you can scan the code for omissions.&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;... do the fixed code from earlier
norm1 = sqrt(x1fixed**2 + y1fixed**2 + z1fixed**2)
norm2 = sqrt(x2fixed**2 + y2fixed**2 + z2fixed**2)
norm12 = norm1 * norm2
if(norm12.lt.eta) ifail=-1, return
angle=acos( (x1fixed*x2fixed+y1*y2fixed+z1fixed*z2fixed)/norm12 )
&lt;/PRE&gt;

&lt;P&gt;The ..fixed numbers are on the order of 0.3, the norms are on the order of sqrt(2.7) or 1.65, the inner expression of acos is on the order of 1.&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2014 19:57:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010381#M105806</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2014-05-09T19:57:02Z</dc:date>
    </item>
    <item>
      <title>norm2 is an F2008 instrinsic</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010382#M105807</link>
      <description>&lt;P&gt;norm2 is an F2008 instrinsic function BTW chaps....&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 May 2014 21:23:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010382#M105807</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2014-05-09T21:23:20Z</dc:date>
    </item>
    <item>
      <title>The code snip is abstract.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010383#M105808</link>
      <description>&lt;P&gt;The code snip is abstract. The variable names chosen were those of the referenced snip from the prior post. Changing the name to avoid conflict may have confused the intent.&amp;nbsp; Length1, Length2, and Length1xLength2&amp;nbsp;might have been more appropriate choice of variable names. Also Fortran permits you do define a variable with the same name as an intrinsic function and keywords&amp;nbsp;(REAL :: DO). I don't own a pair of chaps.&lt;/P&gt;

&lt;P&gt;Overflow and Underflow remediation is a technique I am trying to teach. However, while what I've shown will reduce the probability of overflow/underflow it will affect the precision of the result as it adds operations, each with the potential of introducing&amp;nbsp;additional round off error.&lt;/P&gt;

&lt;P&gt;Mincheol will have to take these issues under consideration when crafting the code to perform the desired functionality (or find a robust enough library function that performs in the manner desired).&lt;/P&gt;

&lt;P&gt;BTW your #4 suggestion is likely the way to go... unless norm2 suffers the overflow under certain input conditions, and then you may need to pre-condition the input vectors prior to passing on to norm2.&lt;/P&gt;

&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Sat, 10 May 2014 12:54:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010383#M105808</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2014-05-10T12:54:10Z</dc:date>
    </item>
    <item>
      <title>Sorry for my mistake in</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010384#M105809</link>
      <description>&lt;P&gt;Sorry for my mistake in omitting the square root in the final ACOS statement.&lt;BR /&gt;
	Using the square of the modulus ( and not taking the&amp;nbsp; square root) for the tests and&lt;BR /&gt;
	putting the square root in the ACOS argument avoids taking an extra square root earlier, thus saving several machine cycles.&lt;/P&gt;</description>
      <pubDate>Mon, 12 May 2014 07:23:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010384#M105809</guid>
      <dc:creator>Anthony_Richards</dc:creator>
      <dc:date>2014-05-12T07:23:48Z</dc:date>
    </item>
    <item>
      <title>My experience of this in</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010385#M105810</link>
      <description>&lt;P&gt;My experience of this in legacy code that gets called millions of times is that atan2 is always better than acos for several reasons:&lt;/P&gt;

&lt;OL&gt;
	&lt;LI&gt;You might think that if you have two normalized vectors _s_ &amp;amp; _t_ then acos(_s_._t_) will always give you the angle between them but you'd be wrong. In practice rounding error can push the dot product outside the valid range so that |s.t| &amp;gt; 1. When this happens the failure is silent - you get an angle but not what you expect. The solution to this is to add guard code, which should be packaged into a function if you're doing it in more than one place, at which point you realize that there ought to be a simpler way and you'd be right - atan2.&lt;/LI&gt;
	&lt;LI&gt;atan2 is faster than acos (in my tests anyway).&lt;/LI&gt;
	&lt;LI&gt;I trust that the compiler writers will do a better job than me in handling all the edge cases, accuracy and performance issues which can arise with this calculation and so are best handled by atan2.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Mon, 12 May 2014 12:53:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010385#M105810</guid>
      <dc:creator>Simon_Geard</dc:creator>
      <dc:date>2014-05-12T12:53:00Z</dc:date>
    </item>
    <item>
      <title>With masked move, X = MIN(X,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010386#M105811</link>
      <description>&lt;P&gt;With masked move, X = MIN(X, 1.0), is relatively fast and has no branch instructions. Note, if you already have a test for identity, you might want to use&lt;/P&gt;

&lt;P&gt;pragma&amp;nbsp;REAL :: AlmostOne = 1.0 - TINY(1.0)&lt;/P&gt;

&lt;P&gt;Tthen use X = MIN(X, AlmostOne)&lt;/P&gt;

&lt;P&gt;Of course as to which to use and/or when is subject to your design goal.&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Mon, 12 May 2014 15:44:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Numerically-stable-algorithm-for-the-angle-between-two-vectors/m-p/1010386#M105811</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2014-05-12T15:44:24Z</dc:date>
    </item>
  </channel>
</rss>

