Hi all,

Here is the cross product from math.matrices;
=======================================
: cross-i ( vec1 vec2 -- i )
    over third over second * >r
    swap second swap third * r> - ;

: cross-j ( vec1 vec2 -- j )
    over first over third * >r
    swap third swap first * r> - ;

: cross-k ( vec1 vec2 -- k )
    over first over second * >r
    swap second swap first * r> - ;

: cross ( vec1 vec2 -- vec3 )
    [ cross-i ] 2keep [ cross-j ] 2keep cross-k 3array ;
=======================================
Here is a cleaned up version that uses Eduardo's cleave combinators; the 
combinators structure the stack flow and make the inherent symmetry of 
the cross product definition more visible:
=======================================
<PRIVATE

: x first ; inline
: y second ; inline
: z third ; inline

: i [ [ y ] [ z ] bi* * ] [ [ z ] [ y ] bi* * ] 2bi - ;
: j [ [ z ] [ x ] bi* * ] [ [ x ] [ z ] bi* * ] 2bi - ;
: k [ [ y ] [ x ] bi* * ] [ [ x ] [ y ] bi* * ] 2bi - ;

PRIVATE>

: cross ( vec1 vec2 -- vec3 ) [ i ] [ j ] [ k ] 2tri 3array ;
=======================================

Slava

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to