are all the examples of cross product code on the internet wrong, or am I wrong?

110 views Asked by At

Background: I'm writing some code in fanuc macro b for machining centers with touch probes, but I guess that's kindof irrelevent... anyways, I'm currently writing a little program to take 3 touches on a surface and output a unit normal vector.

Before I started, I did some searching for examples of vector cross products in other programming languages, and of course, I found lots of them. the thing I'm confused about is that none of the examples I found negate the y (or j) term.. this what I found in various forms across the web:

x = Ay * Bz - By * Az

y = Az * Bx - Bz * Ax

z = Ax * By - Bx * Ay

am I missing something? I thought it should look like this:

x = Ay * Bz - By * Az

y = -1 * (Az * Bx - Bz * Ax)

z = Ax * By - Bx * Ay

I mean I feel like I have to be wrong because the entire internet is rarely wrong.. but on paper it only works out when I do it my way...

thanks in advance.

1

There are 1 answers

0
Serge Ballesta On BEST ANSWER

Hmm, I think that the problem is the way you read the examples. Let us look at Wikipedia. I find:

s1 = a2*b3 - a3*b2
s2 = a3*b1 - a1*b3
s3 = a1*b2 - a2*b2

You just write the second line: s2 = -1 * (a1*b3 - a3*b1) which is exactly the same thing...