英文:
are all the examples of cross product code on the internet wrong, or am I wrong?
问题
Background: 我正在为带有触碰探针的加工中心编写一些 Fanuc 宏B代码,但我猜这有点不相关... 不管怎样,我目前正在编写一个小程序,以在一个表面上进行3次触碰并输出单位法向量。
在我开始之前,我在其他编程语言中搜索了一些矢量叉积的示例,当然,我找到了很多。我困惑的是,我找到的所有示例都没有否定y(或j)项... 这是我在网络上以各种形式找到的:
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...
thanks in advance.
答案1
得分: 1
嗯,我认为问题在于你读取示例的方式。让我们看看Wikipedia上的内容:
s1 = a2*b3 - a3*b2
s2 = a3*b1 - a1*b3
s3 = a1*b2 - a2*b2
你只是写了第二行:s2 = -1 * (a1*b3 - a3*b1)
,这其实是完全相同的事情...
英文:
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...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论