// This file is part of Eigen, a lightweight C++ template library // for linear algebra. Eigen itself is part of the KDE project. // // Copyright (C) 2008 Gael Guennebaud // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // // Alternatively, you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of // the License, or (at your option) any later version. // // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License and a copy of the GNU General Public License along with // Eigen. If not, see . #ifndef EIGEN_CROSS_H #define EIGEN_CROSS_H /** \class Cross * * \brief Expression of the cross product of two vectors * * \param Lhs the type of the left-hand side * \param Rhs the type of the right-hand side * * This class represents an expression of the cross product of two 3D vectors. * It is the return type of MatrixBase::cross(), and most * of the time this is the only way it is used. */ template struct ei_traits > { typedef typename Lhs::Scalar Scalar; typedef typename ei_nested::type LhsNested; typedef typename ei_nested::type RhsNested; typedef typename ei_unref::type _LhsNested; typedef typename ei_unref::type _RhsNested; enum { RowsAtCompileTime = 3, ColsAtCompileTime = 1, MaxRowsAtCompileTime = 3, MaxColsAtCompileTime = 1, Flags = ((_RhsNested::Flags | _LhsNested::Flags) & HereditaryBits) | EvalBeforeAssigningBit, CoeffReadCost = NumTraits::AddCost + 2 * NumTraits::MulCost }; }; template class Cross : ei_no_assignment_operator, public MatrixBase > { public: EIGEN_GENERIC_PUBLIC_INTERFACE(Cross) typedef typename ei_traits::LhsNested LhsNested; typedef typename ei_traits::RhsNested RhsNested; Cross(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs) { assert(lhs.isVector()); assert(rhs.isVector()); assert(lhs.size() == 3 && rhs.size() == 3); } private: int _rows() const { return 3; } int _cols() const { return 1; } Scalar _coeff(int i, int) const { return m_lhs[(i+1)%3]*m_rhs[(i+2)%3] - m_lhs[(i+2)%3]*m_rhs[(i+1)%3]; } protected: const LhsNested m_lhs; const RhsNested m_rhs; }; /** \returns an expression of the cross product of \c *this and \a other * * \sa class Cross */ template template const Cross MatrixBase::cross(const MatrixBase& other) const { return Cross(derived(),other.derived()); } #endif // EIGEN_CROSS_H