Can I replace the cross product with the wedge product?

Started by
12 comments, last by errantkid 15 years, 3 months ago
Quote:Original post by yahastu
The cross product has a geometric meaning that is useful in 3 dimensions..what good is it for 2 or n-dimensions, whats the point?

For me, finding orthogonal vectors. If I have n-1 n-dimensional vectors and I want to find an n-dimensional vector that's orthogonal to the rest, I would use something like the wedge product which behaves very similarly to the 3D cross product and produces a result with many of the same properties. It's not done often, but I've definitely run into the need for such a product on occasions.
Advertisement
In my 2D vector class, I also define the same analog as you for a my cross product. I hadn't made the connection to hodge duals, but I'll note that it's also equivalent the determinant of a matrix with the left-hand-side vector is the upper row, and the right-hand-side vector is the lower row.

I think the bigger problem, and you may be powerless to change the matter at your workplace, is that choosing to overload the operators in the way you have is not so good.

Take the following line of code, where A, B, C, D and E are vectors, ^ is the cross product, and + is the standard addition of vectors.

E = A ^ B + C ^ D

What does that line of code do? Have you discovered the issue? Since the order of operations gives ^ a lower precedence than +, the operations are not performed in the order we think they would be, mathematically. To correct the precedence we can apply superfluous parenthesis (E = (A^B)+(C^D)) but that seems error prone, and to be the type of bug that would take forever to find... I don't know, perhaps its not an issue that comes up much in practice.

For my own work, I define dot and cross products as free functions in the same namespace as my vector class -- e.g. Vec3f cross(const Vec3f &lhs, const Vec3f &rhs);

for two dimesional vectors I define float kross(const Vec2f &lhs, const Vec2f &rhs) as my cross-product analog.

throw table_exception("(? ???)? ? ???");

If overloading ^ for cross is how it's done at your work, you may be stuck with it. Nevertheless, I'll go ahead and point out that many people consider such overloads to be a bad idea.

Non-obvious overloads (such as ^ or % for cross or * for dot) make your code less transparent to other programmers, and can lead to bugs related to order of operation (as Ravyne has already pointed out). IMO, named functions (e.g. dot() and cross()) are to be preferred.
Ah, yes unfortunately I am stuck with the ^ operator. (I'll have about 20 people coming down on my head if I try and remove it)
I am quite happy with * as a dot product, but I have to agree that our cross product is pretty bad form. Especially seeing as it can't be used as a binary operator on those other dimensions. But well I have bigger battles to fight :P

In the end I decided to just play it safe and keep everyone happy. So I left the math library alone and added a Determinant function for my specific purpose.

Aside: I don't think operators are intrinsically bad since they can increase readability (mathematicians use mathematical notation after all). It's just a little unfortunate that we're stuck with the ASCII character set and programming language weirdness. You'd need a combination of Latex and a DSL (domain-specific language) to solve that one :) On the other hand, even mathematicians can't always agree on the right notation!

Thanks for all the replies guys

This topic is closed to new replies.

Advertisement