コード例 #1
0
ファイル: PolyLine3D.cs プロジェクト: zjarci/mathnet-spatial
        /// <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);
        }
コード例 #2
0
ファイル: Circle3D.cs プロジェクト: larsniem/mathnet-spatial
 /// <summary>
 /// Create a circle from the midpoint between two points, in a direction along a specified axis
 /// </summary>
 /// <param name="p1">First point on the circumference of the circle</param>
 /// <param name="p2">Second point on the circumference of the circle</param>
 /// <param name="axis">Direction of the plane in which the circle lies</param>
 public Circle3D(Point3D p1, Point3D p2, UnitVector3D axis)
 {
     this.CenterPoint = Point3D.MidPoint(p1, p2);
     this.Axis        = axis;
     this.Radius      = p1.DistanceTo(CenterPoint);
 }