示例#1
0
        /// <summary>
        /// Calculates the perpendicular line from this line to the given point
        /// </summary>
        /// <param name="pointNotOnLine"></param>
        /// <returns></returns>
        public BoundedLine PerpendicularLineTo(CartesianPoint pointNotOnLine)
        {
            GeometricVector betweenPoints        = pointNotOnLine.Subtract(this.PointOnLine);
            GeometricVector normalizedLineVector = this.Vector.Normalize(2);
            double          projectionDistanceOfEndPointAlongLine = betweenPoints.DotProduct(normalizedLineVector);

            GeometricVector vectorAlongLine             = normalizedLineVector.Multiply(projectionDistanceOfEndPointAlongLine);
            CartesianPoint  endPointOfPerpendicularLine = this.PointOnLine.Add(vectorAlongLine);

            GeometricVector result = pointNotOnLine.Subtract(endPointOfPerpendicularLine);

            return(new BoundedLine(endPointOfPerpendicularLine, result));
        }
示例#2
0
        /// <summary>
        /// Calculates the perpendicular line from this line to the given point
        /// </summary>
        /// <param name="pointNotOnLine"></param>
        /// <returns></returns>
        public GeometricVector PerpendicularLineTo(CartesianPoint pointOnLine, CartesianPoint pointToCalculatePerpendicularVectorTo)
        {
            GeometricVector betweenPoints        = pointToCalculatePerpendicularVectorTo.Subtract(pointOnLine);
            GeometricVector normalizedLineVector = this.Normalize(2);
            double          projectionDistanceOfEndPointAlongLine = betweenPoints.DotProduct(normalizedLineVector);

            GeometricVector scaledVectorAlongLine         = normalizedLineVector.Multiply(projectionDistanceOfEndPointAlongLine);
            CartesianPoint  startPointOfPerpendicularLine = pointOnLine.Add(scaledVectorAlongLine);

            GeometricVector result = pointToCalculatePerpendicularVectorTo.Subtract(startPointOfPerpendicularLine);

            return(result);
        }