示例#1
0
        public void CanGetZOfNearlyHorizontalPlane3D()
        {
            var points = new List <Pnt3D>();

            points.Add(new Pnt3D {
                X = 2723729.625, Y = 1251631.61625, Z = 601
            });
            points.Add(new Pnt3D {
                X = 2723531.44625, Y = 1251727.94, Z = 601
            });
            points.Add(new Pnt3D {
                X = 2723633.2675, Y = 1251824.26375, Z = 601
            });

            points[0].Z += 0.001;

            points.Add(points[0]);

            Plane3D plane = Plane3D.FitPlane(points, true);

            foreach (Pnt3D point in points)
            {
                double z = plane.GetZ(point.X, point.Y);
                Console.WriteLine(@"{0}: {1}", point, z);
                Assert.AreEqual(point.Z, z, plane.Epsilon);
            }

            const double farAwayX = -1000000.12345;
            const double farAwayY = -1000000.6789;
            double       z0       = plane.GetZ(farAwayX, farAwayY);

            Assert.AreEqual(0, plane.GetDistanceSigned(farAwayX, farAwayY, z0), plane.Epsilon);
        }
示例#2
0
        public void CanFitHorizontalPlane3D()
        {
            var x = new double[] { 0, 0, 0, 1, 1, 1, 2, 2, 2 };
            var y = new double[] { 1, 2, 3, 1, 2, 3, 1, 2, 3 };
            var z = new double[] { 1, 1, 1, 1, 1, 1, 1, 1, 1 };

            Plane3D plane = FitPlane3D(x, y, z);

            Assert.AreEqual(1, plane.GetZ(-1000, -1000));
            Assert.AreEqual(1, plane.GetZ(1000, 1000));
            Assert.AreEqual(1, plane.GetDistanceAbs(1000, 1000, 0));
            Assert.AreEqual(1, plane.GetUnitNormal().LengthSquared);
        }
示例#3
0
        private static void EnsureCutResult(IList <IGeometry> results,
                                            IPolygon originalPoly,
                                            Plane3D plane,
                                            int expectedResultPartCount)
        {
            double areaSum   = 0;
            var    partCount = 0;

            foreach (IGeometry result in results)
            {
                Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result));

                areaSum +=
                    GeometryUtils.GetParts((IGeometryCollection)result)
                    .Sum(part => ((IArea)part).Area);

                partCount += GeometryUtils.GetParts((IGeometryCollection)result).Count();

                if (plane != null)
                {
                    foreach (IPoint point in GeometryUtils.GetPoints(
                                 (IPointCollection)result))
                    {
                        Assert.AreEqual(plane.GetZ(point.X, point.Y), point.Z, 0.001);
                    }
                }
            }

            Assert.AreEqual(expectedResultPartCount, partCount);
            Assert.IsTrue(
                MathUtils.AreEqual(((IArea)originalPoly).Area, areaSum));
        }
示例#4
0
        public void CanGetDistanceToVerticalPlane3D()
        {
            List <Pnt3D> points = GetVerticalTrianglePoints();

            Plane3D plane = Plane3D.FitPlane(points);

            Console.WriteLine(@"A: " + plane.A);
            Console.WriteLine(@"B: " + plane.B);
            Console.WriteLine(@"C: " + plane.C);
            Console.WriteLine(@"D: " + plane.D);

            Assert.AreEqual(0, plane.C, plane.Epsilon);             // vertical
            Assert.AreEqual(1, plane.GetUnitNormal().LengthSquared);

            Assert.AreEqual(0.89606641473951276, plane.GetUnitNormal().X, plane.Epsilon);
            Assert.AreEqual(0.44392001574143475, plane.GetUnitNormal().Y, plane.Epsilon);

            foreach (Pnt3D point in points)
            {
                double distance = plane.GetDistanceAbs(point.X, point.Y, point.Z);
                Console.WriteLine(@"{0}: {1}", point, distance);
                Assert.AreEqual(0, distance, plane.Epsilon);
            }

            Assert.Catch <InvalidOperationException>(() => plane.GetZ(100, 100));
        }
示例#5
0
        public void CanDeterminePlaneCoincidence()
        {
            var x = new double[] { 0, 0, 1, 1, 0 };
            var y = new double[] { 0, 1, 1, 0, 0 };
            var z = new double[] { 0, 10, 10, 0, 0 };

            Plane3D plane1 = FitPlane3D(x, y, z, true);

            var points2 = new List <Pnt3D>();

            points2.Add(new Pnt3D(234, 567, plane1.GetZ(234, 567)));
            points2.Add(new Pnt3D(987, 654, plane1.GetZ(987, 654)));
            points2.Add(new Pnt3D(-432, 881, plane1.GetZ(432, 881)));

            Plane3D plane2 = Plane3D.FitPlane(points2);

            Assert.False(plane1.Equals(plane2));
            Assert.True(plane1.IsCoincident(plane2));
        }
示例#6
0
        public void CanGetDistanceToNearlyVerticalPlane3D()
        {
            List <Pnt3D> points = GetVerticalTrianglePoints();

            points[0].Y += 0.01;
            Plane3D plane = Plane3D.FitPlane(points);

            foreach (Pnt3D point in points)
            {
                double distance = plane.GetDistanceAbs(point.X, point.Y, point.Z);
                Console.WriteLine(@"{0}: {1}", point, distance);
                Assert.AreEqual(0, distance, plane.Epsilon);
            }

            double definedZ = plane.GetZ(100, 100);

            Assert.AreEqual(0, plane.GetDistanceAbs(100, 100, definedZ), plane.Epsilon);
        }
示例#7
0
        public static void AssignZ([NotNull] IPointCollection points,
                                   [NotNull] Plane3D fromPlane)
        {
            Assert.False(points is IMultiPatch,
                         "This method cannot be used on multipatch geometries.");

            IEnumVertex eVertex = points.EnumVertices;
            IPoint      point   = new PointClass();
            int         part;
            int         vertex;

            eVertex.QueryNext(point, out part, out vertex);
            while (part >= 0 && vertex >= 0)
            {
                // This crashes ArcMap (with AccessViolation) if called on multipatch geometry:
                eVertex.put_Z(fromPlane.GetZ(point.X, point.Y));
                eVertex.QueryNext(point, out part, out vertex);
            }
        }
 private static AoIntersectionPoint GetIntersectionPoint(
     [NotNull] Plane3D plane, [NotNull] IPoint pt) =>
 new AoIntersectionPoint(pt, plane.GetZ(pt.X, pt.Y),
                         plane.GetDistanceAbs(pt.X, pt.Y, pt.Z));