Exemple #1
0
    /// <summary>
    /// Add a pyramid (5 vertices and 5 planes) to this fragment.
    /// The pyramid should be given as (topVertex, bottomVertex1, bottomVertex2, bottomVertex3, bottomVertex4).
    /// </summary>
    /// <param name="pyramid">Pyramid given.</param>
    public void PushBackPyramid(List <Vector3> pyramid)
    {
        if (pyramid.Count != 5)
        {
            return;
        }
        Vector3 top = pyramid[0];

        pyramid.RemoveAt(0);
        pyramid = ToolFunction.SortConvexPolygon(pyramid);
        PushBackTetra(new List <Vector3> {
            top, pyramid[0], pyramid[1], pyramid[2]
        });
        PushBackTetra(new List <Vector3> {
            top, pyramid[0], pyramid[3], pyramid[2]
        });
    }
Exemple #2
0
    /// <summary>
    /// Add a triangular prism (6 vertices and 5 planes) to this fragment.
    /// </summary>
    /// <param name="triPrism">Triangular prism given.</param>
    public void PushBackTriPrism(List <Vector3> triPrism)
    {
        if (triPrism.Count != 6)
        {
            return;
        }
        List <int> plane1 = new List <int>(), plane2 = new List <int>();
        int        times = 0;

        for (int i1 = 0; i1 < 6; i1++)
        {
            for (int i2 = i1 + 1; i2 < 6; i2++)
            {
                for (int i3 = i2 + 1; i3 < 6; i3++)
                {
                    for (int i4 = i3 + 1; i4 < 6; i4++)
                    {
                        if (ToolFunction.IsCoplanar(triPrism[i1], triPrism[i2], triPrism[i3], triPrism[i4]))
                        {
                            times++;
                            if (times == 1)
                            {
                                plane1.AddRange(new int[] { i1, i2, i3, i4 });
                            }
                            else
                            {
                                plane2.AddRange(new int[] { i1, i2, i3, i4 });
                                goto out_loop;
                            }
                        }
                    }
                }
            }
        }
out_loop:
        List <int> intersect = new List <int>();

        foreach (int i in plane1)
        {
            if (plane2.Contains(i))
            {
                intersect.Add(i);
                plane2.Remove(i);
            }
        }
        foreach (int i in intersect)
        {
            plane1.Remove(i);
        }
        // For ABC-DEF
        // vertices1: ADEB
        List <Vector3> vertices1 = ToolFunction.SortConvexPolygon(new List <Vector3> {
            triPrism[intersect[0]], triPrism[intersect[1]], triPrism[plane1[0]], triPrism[plane1[1]]
        });
        // vertices2: ADFC
        List <Vector3> vertices2 = ToolFunction.SortConvexPolygon(new List <Vector3> {
            triPrism[intersect[0]], triPrism[intersect[1]], triPrism[plane2[0]], triPrism[plane2[1]]
        });

        // tetra F-ABC
        PushBackTetra(new List <Vector3> {
            vertices2[2], vertices1[0], vertices1[3], vertices2[3]
        });
        // tetra F-ABE
        PushBackTetra(new List <Vector3> {
            vertices2[2], vertices1[0], vertices1[3], vertices1[2]
        });
        // tetra F-ADE
        PushBackTetra(new List <Vector3> {
            vertices2[2], vertices1[0], vertices1[1], vertices1[2]
        });
    }