考虑到3分,我该如何计算法向矢量? [英] Given 3 pts, how do I calculate the normal vector?
本文介绍了考虑到3分,我该如何计算法向矢量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
提供三个3D点(A,B和C)如何计算法向矢量?的三个点确定一个平面,我想垂直于该平面的向量。
Given three 3D points (A,B, & C) how do I calculate the normal vector? The three points define a plane and I want the vector perpendicular to this plane.
我可以得到样品C#code,它说明了这一点?
Can I get sample C# code that demonstrates this?
推荐答案
这取决于点的顺序。如果点在一个逆时针顺序指定为从一个方向看的相对正常的,那么它的简单计算:
It depends on the order of the points. If the points are specified in a counter-clockwise order as seen from a direction opposing the normal, then it's simple to calculate:
Dir = (B - A) x (C - A)
Norm = Dir / len(Dir)
其中, X
是交叉产品。
如果您使用的是OpenTK或XNA(可以访问Vector3类型类),那么它的简单的问题:
If you're using OpenTK or XNA (have access to the Vector3 class), then it's simply a matter of:
class Triangle {
Vector3 a, b, c;
public Vector3 Normal {
get {
var dir = Vector3.Cross(b - a, c - a);
var norm = Vector3.Normalize(dir);
return norm;
}
}
}
这篇关于考虑到3分,我该如何计算法向矢量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文