给定 3 点,我如何计算法线向量? [英] Given 3 points, how do I calculate the normal vector?

查看:18
本文介绍了给定 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆