获得Point3D的正常

时间:2013-07-03 10:32:50

标签: c# math geometry vector-graphics

我有一套要点。我使用这些点创建了条带三角形。

enter image description here

我正在使用HelixToolkit绘制这些矩形。函数需要指针列表(三角形将使用三角形条带)和一组法向矢量。现在我需要计算正常。我认为每个三角形应该是正常的。但是功能说每个点都会有正常现象。我使用三个点计算三角形的法线,但如何计算一个点的法线。

因此,如果使用图中所示的示例,所有点(A,B,C,D,E,F)的正常情况。

这是我打电话的方法。

/// <summary>
/// Adds a triangle strip to the mesh.
/// </summary>
/// <param name="stripPositions">
/// The points of the triangle strip.
/// </param>
/// <param name="stripNormals">
/// The normal vectors of the triangle strip.
/// </param>
/// <param name="stripTextureCoordinates">
/// The texture coordinates of the triangle strip.
/// </param>
/// <remarks>
/// See http://en.wikipedia.org/wiki/Triangle_strip.
/// </remarks>
public void AddTriangleStrip(
    IList<Point3D> stripPositions,
    IList<Vector3D> stripNormals = null,
    IList<Point> stripTextureCoordinates = null)

这就是我所拥有的。

var points = new List<Point3D>();
// populate points.
// TODO: populate Normal for each point.
AddTriangleStrip(points, normal);

我用这种方法来计算表面的法线。

private static Vector3D CalculateNormal(Point3D firstPoint, Point3D secondPoint, Point3D thirdPoint)
{
    var u = new Point3D(firstPoint.X - secondPoint.X,
        firstPoint.Y - secondPoint.Y,
        firstPoint.Z - secondPoint.Z);

    var v = new Point3D(secondPoint.X - thirdPoint.X,
        secondPoint.Y - thirdPoint.Y,
        secondPoint.Z - thirdPoint.Z);

    return new Vector3D(u.Y * v.Z - u.Z * v.Y, u.Z * v.X - u.X * v.Z, u.X * v.Y - u.Y * v.X);
}

1 个答案:

答案 0 :(得分:1)

没有像普通的这样的概念。 Normal是指 surface 而不是某个点,所以我推测我们在这里谈论的是给定点的所有邻居面的平均法线

为此,你应该从某一点知道所有连接到它的面孔。 对于每个面部计算其正常值并使其平均值

希望这有帮助。