Beispiel #1
0
        void make_seed(List <Vector3> points)
        {
            //initialize Faces
            Faces = new List <Face>(4);
            //find min-max points of a set
            Vector3 min_xv, max_xv, min_yv, max_yv, min_zv, max_zv;
            float   min_x, max_x, min_y, max_y, min_z, max_z;

            min_xv = max_xv = min_yv = max_yv = min_zv = max_zv = points[0];
            min_x  = max_x = min_xv.x;
            min_y  = max_y = min_xv.y;
            min_z  = max_z = min_xv.z;
            for (int i = 1, pointsCount = points.Count; i < pointsCount; i++)
            {
                Vector3 p = points[i];
                if (p.x < min_x)
                {
                    min_x = p.x; min_xv = p;
                }
                else if (p.x > max_x)
                {
                    max_x = p.x; max_xv = p;
                }

                if (p.y < min_y)
                {
                    min_y = p.y; min_yv = p;
                }
                else if (p.y > max_y)
                {
                    max_y = p.y; max_yv = p;
                }

                if (p.z < min_z)
                {
                    min_z = p.z; min_zv = p;
                }
                else if (p.z > max_z)
                {
                    max_z = p.z; max_zv = p;
                }
            }
            //find the longest line segment between the extremums of each dimension
            var         xl = new LineSegment(min_xv, max_xv);
            var         yl = new LineSegment(min_yv, max_yv);
            var         zl = new LineSegment(min_zv, max_zv);
            LineSegment ml = new [] { xl, yl, zl }.Max();
            //find the furthest point from the longest line
            var     EP  = new [] { min_xv, max_xv, min_yv, max_yv, min_zv, max_zv };
            Vector3 mv1 = EP.SelectMax(ml.DistanceTo);
            //make a face and find the furthest point from it
            var     f0  = new Face(ml.s, ml.e, mv1);
            Vector3 mv2 = EP.SelectMax(p => Math.Abs(f0.P.GetDistanceToPoint(p)));

            //make other 3 faces
            f0.Orient(mv2); //f0 is not visible now,
            //so its edges should be taken in the oposite direction
            var edges = new List <Face.Edge>(3);

            edges.Add(f0.GetEdge(2));
            edges.Add(f0.GetEdge(1));
            edges.Add(f0.GetEdge(0));
            var faces = make_pyramid(mv2, edges);

            Faces.Add(f0); Faces.AddRange(faces);
            points.RemoveAll(v => v.Equals(mv1) || v.Equals(mv2) || v.Equals(ml.s) || v.Equals(ml.e));
        }
Beispiel #2
0
 public Edge(Face host, int index)
 {
     Host  = host;
     Index = index;
 }
Beispiel #3
0
 public void Join(int edge, Face other, int other_edge)
 {
     Join(edge, other.GetEdge(other_edge));
 }