#ifndef vnl_cross_h_ #define vnl_cross_h_ //: // \file // Implements cross product for vectors. // \author Amitha Perera // \verbatim // Modifications // Oct.2002 - Amitha Perera - moved from vnl_vector.h // \endverbatim #include #include #include #include "vnl/vnl_export.h" //: Compute the 2-D cross product // \relatesalso vnl_vector template inline T vnl_cross_2d( const vnl_vector& v1, const vnl_vector& v2 ) { assert( v1.size() >= 2 && v2.size() >= 2 ); return v1[0] * v2[1] - v1[1] * v2[0]; } //: Compute the 2-D cross product // \relatesalso vnl_vector_fixed template inline T vnl_cross_2d( const vnl_vector_fixed& v1, const vnl_vector_fixed& v2 ) { return v1[0] * v2[1] - v1[1] * v2[0]; } //: Compute the 2-D cross product // \relatesalso vnl_vector // \relatesalso vnl_vector_fixed template inline T vnl_cross_2d(vnl_vector_fixed const& v1, vnl_vector const& v2) { assert( v2.size() == 2 ); return v1[0] * v2[1] - v1[1] * v2[0]; } //: Compute the 2-D cross product // \relatesalso vnl_vector // \relatesalso vnl_vector_fixed template inline T vnl_cross_2d(vnl_vector const& v1, vnl_vector_fixed const& v2) { assert( v1.size() == 2 ); return v1[0] * v2[1] - v1[1] * v2[0]; } //: Compute the 3-D cross product // \relatesalso vnl_vector template inline vnl_vector vnl_cross_3d( const vnl_vector& v1, const vnl_vector& v2 ) { assert( v1.size() == 3 && v2.size() == 3 ); vnl_vector result(3); result[0] = v1[1] * v2[2] - v1[2] * v2[1]; // work for both col/row result[1] = v1[2] * v2[0] - v1[0] * v2[2]; // representation result[2] = v1[0] * v2[1] - v1[1] * v2[0]; return result; } //: Compute the 3-D cross product // \relatesalso vnl_vector_fixed template inline vnl_vector_fixed vnl_cross_3d( const vnl_vector_fixed& v1, const vnl_vector_fixed& v2 ) { vnl_vector_fixed result; result[0] = v1[1] * v2[2] - v1[2] * v2[1]; // work for both col/row result[1] = v1[2] * v2[0] - v1[0] * v2[2]; // representation result[2] = v1[0] * v2[1] - v1[1] * v2[0]; return result; } //: Compute the 3-D cross product // \relatesalso vnl_vector // \relatesalso vnl_vector_fixed template inline vnl_vector_fixed vnl_cross_3d( const vnl_vector_fixed& a, const vnl_vector& b ) { return vnl_cross_3d(a.as_ref(), b); } //: Compute the 3-D cross product // \relatesalso vnl_vector // \relatesalso vnl_vector_fixed template inline vnl_vector_fixed vnl_cross_3d( const vnl_vector& a, const vnl_vector_fixed& b ) { return vnl_cross_3d(a, b.as_ref()); } #endif // vnl_cross_h_