Click or drag to resize

Point2dDistanceTo Method

Computes the distance between two points.

Namespace:  Rhino.Geometry
Assembly:  RhinoCommon (in RhinoCommon.dll)
Syntax
public double DistanceTo(
	Point2d other
)

Parameters

other
Type: Rhino.GeometryPoint2d
Another point.

Return Value

Type: Double
The length of the line between the two points, or 0 if either point is invalid.
Examples
using Rhino;
using Rhino.Geometry;
using Rhino.Commands;
using System.Collections.Generic;
using System.Linq;

namespace examples_cs
{
  public class LeaderCommand : Command
  {
    public override string EnglishName { get { return "csLeader"; } }

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var points = new Point3d[]
      {
        new Point3d(1, 1, 0),
        new Point3d(5, 1, 0),
        new Point3d(5, 5, 0),
        new Point3d(9, 5, 0)
      };

      var xy_plane = Plane.WorldXY;

      var points2d = new List<Point2d>();
      foreach (var point3d in points)
      {
        double x, y;
        if (xy_plane.ClosestParameter(point3d, out x, out y))
        {
          var point2d = new Point2d(x, y);
          if (points2d.Count < 1 || point2d.DistanceTo(points2d.Last<Point2d>()) > RhinoMath.SqrtEpsilon)
            points2d.Add(point2d);
        }
      }

      doc.Objects.AddLeader(xy_plane, points2d);
      doc.Views.Redraw();
      return Result.Success;
    }
  }
}
import rhinoscriptsyntax as rs

def RunCommand():
  points = [(1,1,0), (5,1,0), (5,5,0), (9,5,0)]
  rs.AddLeader(points)

if __name__ == "__main__":
    RunCommand()
Version Information

Rhino for Mac

Supported in: 5.4

Rhino for Windows

Supported in: 6.6
See Also