mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Cross product for vectors of size 2. Fixes #1037
This commit is contained in:
committed by
Antonio Sánchez
parent
8588d8c74b
commit
6431dfdb50
@@ -367,7 +367,8 @@ vec2 = vec1.normalized(); vec1.normalize(); // inplace \endcode
|
||||
<tr class="alt"><td>
|
||||
\link MatrixBase::cross() cross product \endlink \matrixworld</td><td>\code
|
||||
#include <Eigen/Geometry>
|
||||
vec3 = vec1.cross(vec2);\endcode</td></tr>
|
||||
v3c = v3a.cross(v3b); // size-3 vectors
|
||||
scalar = v2a.cross(v2b); // size-2 vectors \endcode</td></tr>
|
||||
</table>
|
||||
|
||||
<a href="#" class="top">top</a>
|
||||
|
||||
@@ -158,7 +158,7 @@ For dot product and cross product, you need the \link MatrixBase::dot() dot()\en
|
||||
\verbinclude tut_arithmetic_dot_cross.out
|
||||
</td></tr></table>
|
||||
|
||||
Remember that cross product is only for vectors of size 3. Dot product is for vectors of any sizes.
|
||||
Cross product is defined in Eigen not only for vectors of size 3 but also for those of size 2, check \link MatrixBase::cross() the doc\endlink for details. Dot product is for vectors of any sizes.
|
||||
When using complex numbers, Eigen's dot product is conjugate-linear in the first variable and linear in the
|
||||
second variable.
|
||||
|
||||
|
||||
@@ -9,5 +9,10 @@ int main()
|
||||
std::cout << "Dot product: " << v.dot(w) << std::endl;
|
||||
double dp = v.adjoint()*w; // automatic conversion of the inner product to a scalar
|
||||
std::cout << "Dot product via a matrix product: " << dp << std::endl;
|
||||
|
||||
std::cout << "Cross product:\n" << v.cross(w) << std::endl;
|
||||
Eigen::Vector2d v2(1,2);
|
||||
Eigen::Vector2d w2(0,1);
|
||||
double cp = v2.cross(w2); // returning a scalar between size-2 vectors
|
||||
std::cout << "Cross product for 2D vectors: " << cp << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user