# 在互联网上的所有叉积代码示例都是错误的吗，还是我错了？

go评论75阅读模式

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

# 问题

Background: 我正在为带有触碰探针的加工中心编写一些 Fanuc 宏B代码，但我猜这有点不相关... 不管怎样，我目前正在编写一个小程序，以在一个表面上进行3次触碰并输出单位法向量。

x = Ay * Bz - By * Az

y = Az * Bx - Bz * Ax

z = Ax * By - Bx * Ay

x = Ay * Bz - By * Az

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

z = Ax * By - Bx * Ay

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...

# 答案1

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

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...

• 本文由 发表于 2020年10月1日 22:43:28
• 转载请务必保留本文链接：https://go.coder-hub.com/64157736.html
• c
• java
• math
• vector
• vectormath

go 68

go 62

go 70

go 60