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 点,我如何计算法线向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:给定 3 点,我如何计算法线向量?


- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 使用 rss + c# 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01