Example #1
0
        /// <summary>
        /// calculate tetrahedrone involved all points
        /// </summary>
        /// <param name="pVectorList">xyz point list</param>
        /// <returns>tetrahedrone</returns>
        private static Tetrahedron GetFirstTetra(List <PVector> pVectorList)
        {
            float xMin = pVectorList.Min(value => value.X);
            float yMin = pVectorList.Min(value => value.Y);
            float zMin = pVectorList.Min(value => value.Z);

            float xMax = pVectorList.Max(value => value.X);
            float yMax = pVectorList.Max(value => value.Y);
            float zMax = pVectorList.Max(value => value.Z);

            //rectangular solid size
            float width  = xMax - xMin;
            float height = yMax - yMin;
            float depth  = zMax - zMin;

            //center of globe
            float   cX     = width / 2 + xMin;
            float   cY     = height / 2 + yMin;
            float   cZ     = depth / 2 + zMin;
            PVector center = new PVector(cX, cY, cZ);

            //radius
            //0.1f is addition
            float radius = Common.GetDist(new PVector(xMax, yMax, zMax), new PVector(xMin, yMin, zMin)) / 2 + 0.1f;

            PVector p1 = new PVector(center.X, center.Y + 3.0f, center.Z);
            PVector p2 = new PVector(center.X + (float)2 * (float)Math.Sqrt(2) * radius, center.Y - radius, center.Z);
            PVector p3 = new PVector(-(float)Math.Sqrt(2) * radius + center.X, -radius + center.Y, (float)Math.Sqrt(6) * radius + center.Z);
            PVector p4 = new PVector(-(float)Math.Sqrt(2) * radius + center.X, -radius + center.Y, -(float)Math.Sqrt(6) * radius + center.Z);

            return(new Tetrahedron(p1, p2, p3, p4));
        }
Example #2
0
        /// <summary>
        /// calculate radius and circle of outer circle from tetrahedron points
        /// ref URL http://www.openprocessing.org/sketch/31295
        /// </summary>
        private void getCenterCircumcircle()
        {
            //translation from P1
            double[,] A = new double[, ] {
                { P2.X - P1.X, P2.Y - P1.Y, P2.Z - P1.Z },
                { P3.X - P1.X, P3.Y - P1.Y, P3.Z - P1.Z },
                { P4.X - P1.X, P4.Y - P1.Y, P4.Z - P1.Z }
            };
            //I did not understand this mean
            double[] b = new double[] {
                0.5 * (P2.X * P2.X - P1.X * P1.X + P2.Y * P2.Y - P1.Y * P1.Y + P2.Z * P2.Z - P1.Z * P1.Z),
                0.5 * (P3.X * P3.X - P1.X * P1.X + P3.Y * P3.Y - P1.Y * P1.Y + P3.Z * P3.Z - P1.Z * P1.Z),
                0.5 * (P4.X * P4.X - P1.X * P1.X + P4.Y * P4.Y - P1.Y * P1.Y + P4.Z * P4.Z - P1.Z * P1.Z)
            };

            //solve
            double[] x = new double[3];
            if (gauss(A, b, x) == 0)
            {
                O = null;
                R = -1;
            }
            else
            {
                O = new PVector((float)x[0], (float)x[1], (float)x[2]);
                R = Common.GetDist(O, P1);
            }
        }
Example #3
0
        /// <summary>
        /// Calculate Delaunay Triangulation
        /// </summary>
        /// <param name="pVectorList">AllPoints</param>
        /// <returns>Tetrahedrone List</returns>
        private List <Tetrahedron> GetTetraList(List <PVector> pVectorList)
        {
            List <Tetrahedron> tetraList = new List <Tetrahedron>();

            tetraList.Add(this.FirstTetra);

            List <Tetrahedron> tmpTList    = new List <Tetrahedron>();
            List <Tetrahedron> newTList    = new List <Tetrahedron>();
            List <Tetrahedron> removeTList = new List <Tetrahedron>();

            foreach (var point in pVectorList)
            {
                tmpTList.Clear();
                newTList.Clear();
                removeTList.Clear();

                foreach (var t in tetraList)
                {
                    if ((t.O != null) &&
                        (t.R > Common.GetDist(point, t.O)))
                    {
                        tmpTList.Add(t);
                    }
                }

                foreach (var t1 in tmpTList)
                {
                    tetraList.Remove(t1);

                    PVector v1 = t1.P1;
                    PVector v2 = t1.P2;
                    PVector v3 = t1.P3;
                    PVector v4 = t1.P4;

                    newTList.Add(new Tetrahedron(v1, v2, v3, point));
                    newTList.Add(new Tetrahedron(v1, v2, v4, point));
                    newTList.Add(new Tetrahedron(v1, v3, v4, point));
                    newTList.Add(new Tetrahedron(v2, v3, v4, point));
                }

                bool[] isRedundancy = new bool[newTList.Count];
                for (int i = 0; i < newTList.Count - 1; i++)
                {
                    for (int j = i + 1; j < newTList.Count; j++)
                    {
                        if (newTList[i].Equal(newTList[j]))
                        {
                            isRedundancy[i] = isRedundancy[j] = true;
                        }
                    }
                }

                for (int i = 0; i < newTList.Count; i++)
                {
                    if (!isRedundancy[i])
                    {
                        tetraList.Add(newTList[i]);
                    }
                }
            }

            PVector[] outer   = new PVector[] { this.FirstTetra.P1, this.FirstTetra.P2, this.FirstTetra.P3, this.FirstTetra.P4 };
            bool      isOuter = false;
            var       count   = 0;

            for (int i = tetraList.Count - 1; i >= 0; i--)
            {
                isOuter = false;
                foreach (var t4Point in tetraList[i].Vertices)
                {
                    foreach (var outerPoint in outer)
                    {
                        if (t4Point.X == outerPoint.X &&
                            t4Point.Y == outerPoint.Y &&
                            t4Point.Z == outerPoint.Z)
                        {
                            isOuter = true;
                        }
                    }
                }
                if (isOuter)
                {
                    tetraList.RemoveAt(i);
                    count++;
                    Console.WriteLine(count);
                }
            }

            return(tetraList);
        }