Finding Longest Distance between set points on C# / Grasshopper

Hi, I have a drone simulation in which I can set points to be used as anchors for the drone to reach, I want the drone to go from Point A (the first point from the points the user has created) to finding the point that is the longest distance from Point A and assigning it as Point B, here is a visual to help understand:

image

Currently this is what I have written in C#:

I assumed that the origin point(0, 0, 0) is in the quad angle from 4 points and calculated angle of 4 points with x-axis, which if the points are in a square, will make the drone go from point A to B:


But when the points are not in a square, it will still go across even though the point is not the longest distance:

I was wondering if there is a solution to this ideally in C# but Grasshopper will work as I can understand the method and translate it.

Thank you :smiley:

Big Brother is always watching :wink:

using System.Linq;

private void RunScript(Point3d refPt, List<Point3d> cloudPt, ref object A)
  {
    List<Point3d> sorted = cloudPt.OrderBy(x => x.DistanceTo(refPt)).ToList<Point3d>();

    A = sorted[sorted.Count - 1];
  }

LinqFurthestPoint.gh (10.8 KB)

2 Likes

:sunglasses: :fist_right: :fist_left: