Exemple #1
0
        public LineSegment3D Project(LineSegment3D line3DToProject)
        {
            var projectedStartPoint = this.Project(line3DToProject.StartPoint);
            var projectedEndPoint   = this.Project(line3DToProject.EndPoint);

            return(new LineSegment3D(projectedStartPoint, projectedEndPoint));
        }
        /// <summary>
        /// Returns the closest point on the polyline to the given point.
        /// </summary>
        /// <param name="p">A point</param>
        /// <returns>A point which is the closest to the given point but still on the line.</returns>
        public Point3D ClosestPointTo(Point3D p)
        {
            var minError = double.MaxValue;
            var closest  = default(Point3D);

            for (var i = 0; i < this.VertexCount - 1; i++)
            {
                var segment   = new LineSegment3D(this.points[i], this.points[i + 1]);
                var projected = segment.ClosestPointTo(p);
                var error     = p.DistanceTo(projected);
                if (error < minError)
                {
                    minError = error;
                    closest  = projected;
                }
            }

            return(closest);
        }
 /// <summary>
 /// Transforms a line segment.
 /// </summary>
 /// <param name="l">A line segment</param>
 /// <returns>The transformed line segment</returns>
 public LineSegment3D Transform(LineSegment3D l)
 {
     return(new LineSegment3D(this.Transform(l.StartPoint), this.Transform(l.EndPoint)));
 }