public void Create_2dPoints_ReturnHyperplane()
        {
            PlanePoint[] points = new PlanePoint[]
            {
                new PlanePoint(new double[] { 0, 0 }),
                new PlanePoint(new double[] { 0, 4 })
            };
            Vector     normal = new Vector(new double[] { -1, 0 });
            Hyperplane h2     = new Hyperplane(points[0], normal);

            Hyperplane h = Hyperplane.Create(points);

            Assert.AreEqual(h2, h);
        }
        public void Create_2dPoints_ReturnHyperplane2()
        {
            PlanePoint[] points = new PlanePoint[]
            {
                new PlanePoint(new double[] { 2, 1 }),
                new PlanePoint(new double[] { 1, 1 })
            };

            Hyperplane h = Hyperplane.Create(points);

            double y = h.Normal[0] * (-1);
            double t = 9 / y;

            Assert.IsTrue(true);
        }
示例#3
0
        public IConvexHull FindConvexHull(IList <PlanePoint> points)
        {
            int dim = points[0].Dim;

            if (dim == 2)
            {
                return(new ConvexHull2d(points));
            }
            ConvexHull convexHull = new ConvexHull(dim);

            PlanePoint[] planePoints = new PlanePoint[points.Count - 1];
            for (int i = 0; i < points.Count; i++)
            {
                int k = 0;
                for (int j = 0; j < points.Count; j++)
                {
                    if (j == i)
                    {
                        continue;
                    }
                    planePoints[k++] = points[j];
                }
                Hyperplane        hyperplane    = Hyperplane.Create(planePoints);
                List <PlanePoint> convertPoints =
                    planePoints.Select((point => hyperplane.ConvertPoint(point))).ToList();
                Face newFace = new Face(hyperplane);
                newFace.ConvexHull = FindConvexHull(convertPoints);
                foreach (ICell f in newFace.ConvexHull.Cells)
                {
                    newFace.AdjacentCells.Add((IFace)f);
                    ((IFace)f).AdjacentCells.Add(newFace);
                }

                convexHull.AddInnerCell(newFace);
            }

            return(convexHull);
        }
        private IConvexHull FindConvexHullNd(IList <PlanePoint> points)
        {
            int dim = points[0].Dim;

            Hyperplane        firstPlane = _planeFinder.FindFirstPlane(points);
            CuratorConvexHull curator    = new CuratorConvexHull(firstPlane);

            foreach (IFace currentFace in curator.GetFaces())
            {
                bool[]            pointsMap   = new bool[points.Count];
                List <PlanePoint> planePoints = new List <PlanePoint>();
                for (int i = 0; i < points.Count; i++)
                {
                    if (!currentFace.Hyperplane.IsPointInPlane(points[i]))
                    {
                        continue;
                    }
                    pointsMap[i] = true;
                    planePoints.Add(currentFace.Hyperplane.ConvertPoint(points[i]));
                }

                currentFace.ConvexHull = FindConvexHull(planePoints);

                if (planePoints.Count == points.Count)
                {
                    return(currentFace.ConvexHull);
                }
                foreach (ICell edge in currentFace.ConvexHull.Cells)
                {
                    Hyperplane facePlane   = currentFace.Hyperplane;
                    Vector     innerVector = facePlane.ConvertVector(-edge.Hyperplane.Normal);
                    PlanePoint mainPoint   = edge.Hyperplane.MainPoint.GetPoint(dim);
                    Vector[]   edgeBasis   = edge.Hyperplane.Basis.Select(facePlane.ConvertVector).ToArray();

                    double minCos     = double.MaxValue;
                    Vector nextVector = default;
                    for (int i = 0; i < points.Count; i++)
                    {
                        if (pointsMap[i])
                        {
                            continue;
                        }
                        Vector newVector = Point.ToVector(mainPoint, points[i]);
                        newVector = edgeBasis.GetOrthonormalVector(newVector);
                        if (Tools.EQ(newVector.Length))
                        {
                            continue;
                        }
                        double newCos = newVector.Cos(innerVector);
                        if (Tools.GT(newCos, minCos))
                        {
                            continue;
                        }
                        minCos     = newCos;
                        nextVector = newVector;
                    }

                    Vector[]   newFaceBasis   = CreateFaceBasis(edgeBasis, nextVector);
                    Hyperplane nextHyperplane = Hyperplane.Create(mainPoint, newFaceBasis);
                    nextHyperplane.SetOrientationNormal(planePoints);

                    curator.AddNewPlane(nextHyperplane, currentFace);
                }
            }

            return(curator.GetConvexHull());
        }