给定3分,我该如何计算法向矢量? [英] Given 3 points, 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#代码吗?
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屋!
查看全文