note
Zaxo
<p>A few points on implementation:<ol>
<li>The sub <tt>orthogonal</tt> is not very stable. Floating point numbers should be compared in terms of a small tolerance. A proper choice for two vectors could be pseudocoded as <code>magnitude(v1-v2) < $EPS * sqrt(magnitude(v1)**2 + magnitude(v2)**2);</code> $EPS is epsilon, the builtin precision of floats.</li>
<li>Sub <tt>angle</tt> loses precision for angles near integer multiples of pi. An implementation in terms of <tt>atan2</tt> would be better, extracting sin of the angle from the cross product.</li>
<li>You may prefer to simply return the zero vector from <tt>normalize</tt>, instead of carping out.</li>
<li>You'll find some help in the [cpan://Math::Trig] module. For high performance, take a look at [cpan://Math::GSL] and [cpan://Math::Pari]. If you decide to follow [Masem]'s suggestion to generalize, [cpan://PDL] is another high performance library specializing in arrays of values.</li>
</ol>I implemented some of the sexier parts of this stuff in the [Snippets|snippet] [id://89236].</p>
<p><b>Update: </b>Added #4. <b>U<sup>2</sup>: </b>The pseudocode in #1 is for equality ( <code>==</code> operator). Other comparisons are similarly made.</p>
<p>After Compline,<br/>Zaxo</p>
132457
132457