Eigen 2D cross product
Asked Answered
W

1

6

Can Eigen do a 2D cross product?

I was trying to replace this code:

Eigen::Vector2f a, b;
float result = a.x()*b.y() - b.x()*a.y();

With this:

Eigen::Vector2f a, b;
float result = a.cross(b);

However, this gives me the following error:

error C2338: THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE

Update

Of course Avi Ginsburg is right and its not really defined. So to clarify: What I'm looking for is the length of the cross product (basically the sine of the angle between the vectors, if I understand it correctly).

Wu answered 8/10, 2015 at 6:21 Comment(4)
This question has already been considered, see this feature request.Battologize
What do you have against the first solution ? You can consider computing the 2x2 determinant.Kilovolt
@YvesDaoust I just thought it would be nicer to use a predefined function for such a "standard" computation, instead of doing the computation myself...Kentigera
For the 2x2 case, using generic functions is most probably overkill.Kilovolt
A
-1

The result of a cross product is a vector, not a float. And anyway, a cross product in 2D doesn't make sense. In 2D the result vector would have to be perpendicular to both a and b and they already define the plane, so the result would have to be in the 3rd dimension.

Alkylation answered 8/10, 2015 at 7:15 Comment(2)
Thanks, Updated my questionKentigera
What Jan really wants is the exterior/outer product. This exists for any dimension. For 3D it is the dual of the cross product (pseudo vector) and for 2D the dual of a scalar (pseudo scalar). It would be handy to have this in Eigen. The best way would be to return a row vector for column vector arguments and vice versa. (For 2D unfortunately you cannot distinguish pseudo scalars from scalars just by their dimension (1x1)) See Geometric Algebra for a more rigorous notation.Johathan

© 2022 - 2024 — McMap. All rights reserved.