예제 #1
0
        public double GetDistanceSigned(double x, double y, double z)
        {
            if (!IsDefined)
            {
                throw new InvalidOperationException("Plane is not defined.");
            }

            var v = new Pnt3D(x, y, z);

            double dotProd = GeomUtils.DotProduct(v, A, B, C);

            return((dotProd - D) / LengthOfNormal);
        }
예제 #2
0
        public double?GetIntersectionFactor(Pnt3D lineStart, Pnt3D lineEnd)
        {
            if (!IsDefined)
            {
                throw new InvalidOperationException("Plane is not defined.");
            }

            // Required: any point on the plane p:
            var p = new Pnt3D(Normal * D / LengthOfNormalSquared);

            double denominator = GeomUtils.DotProduct(lineEnd - lineStart, Normal);

            if (MathUtils.AreEqual(denominator, 0))
            {
                // The line is parallel to the plane.
                return(null);
            }

            double t = GeomUtils.DotProduct(p - lineStart, Normal) /
                       denominator;

            return(t);
        }
예제 #3
0
파일: Line3D.cs 프로젝트: ProSuite/ProSuite
        /// <summary>
        /// The perpendicular distance of the infinite line defined by the Start/End points of this
        /// line to the specified point.
        /// </summary>
        /// <param name="point"></param>
        /// <param name="inXY"></param>
        /// <param name="distanceAlongRatio">The distance-along-ratio of the closest point on the line.</param>
        /// <param name="pointOnLine"></param>
        /// <returns></returns>
        public double GetDistancePerpendicular(Pnt3D point, bool inXY,
                                               out double distanceAlongRatio,
                                               out Pnt3D pointOnLine)
        {
            // http://geomalgorithms.com/a02-_lines.html#Distance-to-Infinite-Line

            Pnt3D w = point - StartPoint;

            double c1, c2;

            if (inXY)
            {
                c1 = GeomUtils.DotProduct(w.X, w.Y, 0, DirectionVector.X,
                                          DirectionVector.Y, 0);
                c2 = DirectionVector.Length2DSquared;
            }
            else
            {
                c1 = GeomUtils.DotProduct(w, DirectionVector);
                c2 = DirectionVector.LengthSquared;
            }

            if (c2 < double.Epsilon)
            {
                // 0-length line: Distance to StartPoint
                distanceAlongRatio = 0;
                pointOnLine        = (Pnt3D)StartPoint.Clone();
                return(StartPoint.GetDistance(point, inXY));
            }

            distanceAlongRatio = c1 / c2;

            pointOnLine = (Pnt3D)(StartPoint + distanceAlongRatio * DirectionVector);

            return(pointOnLine.GetDistance(point, inXY));
        }