Summary: | cross products of vectors of dimensions other than 3 | ||
---|---|---|---|
Product: | Eigen | Reporter: | Michael <mishapom> |
Component: | Core - matrix products | Assignee: | Nobody <eigen.nobody> |
Status: | DECISIONNEEDED --- | ||
Severity: | Feature Request | CC: | chtz, gael.guennebaud |
Priority: | Normal | ||
Version: | 3.4 (development) | ||
Hardware: | All | ||
OS: | All | ||
Whiteboard: |
Description
Michael
2015-07-09 22:09:36 UTC
Here's a relevant wikipedia article: https://en.wikipedia.org/wiki/Exterior_algebra Ok, why not. Though probably it would be better to call it `wedge` instead of `cross`, to avoid confusion. Decision-needed: Would it be better, to always return a skew-symmetric NxN matrix? Making special cases for 2 and 3 dims sounds a bit arbitrary, IMO. Also, if we allow wedge for dynamic-sized vectors, we could not return a scalar/vector/matrix depending on the input size. If you only need the 2d case, an alternative would be to provide a rot90 method which rotates a 2d vector by 90 degrees. You could then write: a.rot90().dot(b) to get what you want. IMHO vector output in 3D is more convenient because most people think of a cross product output as a vector rather than a matrix. Similarly, a scalar output in 2D would be more convenient. Returning skew-matrices for general size vectors, including dynamic-sized vectors, could be done by implementing that under a different name; `wedge` that you suggested sounds like a good idea. Then wedge would be applicable for any vectors and return a matrix, and cross would be available only in 2D and 3D, returning scalar for 2D and Vector3 for 3D. VectorXf a(3), b(3); MatrixXf c = a.wedge(b); // Returns 3x3 matrix Vector3f a, b; Vector3f c = a.cross(b); // Returns dim 3 vector VectorXf a(2), b(2); MatrixXf c = a.wedge(b); // Returns 2x2 matrix Vector2f a, b; float c = a.cross(b); // Returns a scalar VectorXf a(10), b(10); MatrixXf c = a.wedge(b); // Returns 10x10 matrix VectorXf a(3), b(3); MatrixXf c = a.cross(b); // Error! cross defined for fixed size 2D or 3D vectors only! cross is not defined for dynamic sized vectors, even if they happen to be of the right size. Vector4f a(10), b(10); MatrixXf c = a.cross(b); // Error! cross defined for fixed size 2D or 3D vectors only! VectorXf a(2), b(3); MatrixXf c = a.wedge(b); // Error! wedge defined for vectors of the same size only! I'm ok to add cross for 2x2. I'm hesitating between calling it "cross" or "cross2" to make it more explicit. For higher dimensions, I'd rather wait for a real need. How about "area" because the result is geometrically signed area of parallelogram spanned by the two vectors? "area" is too specific, for instance this "cross2" operator can also be used on a pair of unit vectors to get their angle' sine. Ok, cross2 sounds good. -- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1037. |