将原始三角形拆分为较小的三角形

时间:2015-01-27 01:28:05

标签: c# wpf tessellation helix-3d-toolkit

我使用Helix Toolkit使用WPF渲染管道。我意识到所提供的功能会生成对我来说太大的三角形基元。

enter image description here

例如,如果红色三角形是我的原始,我想控制(比如说)三角形的中间部分。我能想到的一种方法是将红色三角形进一步分割成蓝色三角形,如图所示。有人能指出我允许这种分裂的方法或算法吗?

1 个答案:

答案 0 :(得分:0)

    public struct Triangle
    {
        public Vector3 point1;
        public Vector3 point2;
        public Vector3 point3;

        public Triangle(Vector3 p1, Vector3 p2, Vector3 p3)
        { 
            this.point1 = p1;
            this.point2 = p2;
            this.point3 = p3; 
        }
    }

    public static Vector3 getMiddlePoint(Vector3 point1, Vector3 point2)
    {
        return new Vector3((point1.X + point2.X) / 2.0f, (point1.Y + point2.Y) / 2.0f, (point1.Z + point2.Z) / 2.0f);
    }

    public static List<Triangle> SplitTriangle(Triangle tri)
    {
        Vector3 a = getMiddlePoint(tri.point1, tri.point2);      
        Vector3 b = getMiddlePoint(tri.point2, tri.point3);
        Vector3 c = getMiddlePoint(tri.point3, tri.point1);
        List<Triangle> NewTris = new List<Triangle>();
        NewTris.Add(new Triangle(tri.point1, a, c));
        NewTris.Add(new Triangle(tri.point2, b, a));
        NewTris.Add(new Triangle(tri.point3, c, b));
        NewTris.Add(new Triangle(a, b, c);
        return NewTris;
    }