This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

| Sarrus Scheme for Cross Products and Determinants Submitted by

Sarrus scheme aka: Sarrus Rule, Rule of Sarrus, The Sarrus Expansion, aka The Enigmatic Sarrus's 12 steps to better Cross products
named for P.F. Sarrus but previously created by Takakazu Seki
Here is a little tip for anyone who ever has trouble remembering how to calculate a cross product. I just picked it up while reading through the appendix of Real-Time Rendering by Akenine-Moller and Haines.
let:

     i  be the X axis,
     j  be the Y axis,
     k  be the Z axis.

given vectors A and vectors B

    A = <Ax,Ay,Az>
    B = <Bx,By,Bz>

list a matrix that looks like this:

    i  j  k
    Ax Ay Az
    Bx By Bz

now write it twice side by side:

    +  +  +      -  -   -
     \  \  \    /  /  /
      i  j  k  i  j  k
      Ax Ay Az Ax Ay Az
      Bx By Bz Bx By Bz

then follow the + and - along the diagonals to add up the terms:

     i*Ay*Bz  +  j*Az*Bx  + k*Ax*By  - i*AzBy - j*AxBz - K*AyBx

gather the terms:

    i(AyBz - AzBy)  +  j(AzBx - AxBz) + k(AxBy - AyBx)

the stuff inside the parenthesis are the components of your new vector

    A cross B =  < (AyBz-AzBy), (AzBx-AxBz), (AxBy-AyBx) >

This same technique can be used to compute the determinant too. I'm sure this is an old trick to some of you, but it's new to me.
may you never forget how to compute a cross product again.
- Clint Brewer

The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.