[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: Cross Product Results

**From**: |
Mario Storti |

**Subject**: |
Re: Cross Product Results |

**Date**: |
Fri, 19 Sep 1997 19:28:11 -0300 |

Sometimes it is useful to perform the cross product on a large number
of pair of vectors. So a and b may be matrices of N x 3 and:
c = cross(a,b)
is N x 3 matrix where each row is the dot product of the corresponding
rows in a and b. The code may be "vectorized" in the row dimension:
>* c(:,1)=a(:,2).*b(:,3)-a(:,3).*b(:,2);*
>* c(:,2)=a(:,3).*b(:,1)-a(:,1).*b(:,3);*
>* c(:,3)=a(:,1).*b(:,2)-a(:,2).*b(:,1);*
This is useful when working with finite element meshes, 3D
representation of surfaces, etc... For instance, if a and b are the
corresponding sides of a large set of triangles, then c is normal to
the triangles and |c| is the area of the triangles.
We could check the dimensions of the arrays since there are no
possible confusion:
>* if a and b are 3x1*
>* compute cross product as column vectors*
>* else if a and b are Nx3*
>* compute cross product as row vectors*
>* elseif*
>* error*
>* endif*
Note that we can't consider a and b of the form 3xN since then there
is an ambiguity when the matrix is 3x3.
I will write such a version and post it to octave-sources in the case
that someone else finds it useful. Send comments or suggestions.
Cheers,
Mario
%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%
Mario Alberto Storti | Fax: (54)(42) 55.09.44 |
Grupo de Tecnologia Mecanica | Tel: (54)(42) 55.91.75 |
INTEC, Guemes 3450 - 3000 Santa Fe | Home: Gob. Vera 3161 |
Argentina | (54)(42) 55.00.23|
Reply: address@hidden | |
http://venus.unl.edu.ar/gtm-eng.html |