Split Arc with XY Plane, staying with upper half, C#

Hi,

I am constructing an arc through points and cut it with the XY-Plane.

I want to stay with the upper half, but it remains the lower one.

Could someone explain what I am doing wrong?

Thanks

private void RunScript(List<Vector3d> vec, ref object A)
  {
    var points = new List<Point3d>(vec.Count);
    foreach (Vector3d vector in vec)
    {
      Point3d pt = new Point3d(vector);
      points.Add(pt);
    }

    Sphere sphere = Sphere.FitSphereToPoints(points);
    Plane plane = new Plane();
    Plane.FitPlaneToPoints(points, out plane);
    Circle circle = new Circle();
    Rhino.Geometry.Intersect.Intersection.PlaneSphere(plane, sphere, out circle);


    double a ; double b;
    var doubles = new List<double>(2);
    Rhino.Geometry.Intersect.Intersection.PlaneCircle(Plane.WorldXY, circle, out a, out b);
    doubles.Add(a);
    doubles.Add(b);

    Curve cirNrbs = circle.ToNurbsCurve();
    Curve[] crvs = cirNrbs.Split(doubles);

    
    for (int i = 0; i < 2; i++)
    {
      Point3d midPt = crvs[i].PointAtNormalizedLength(0.5);
      if (midPt.DistanceTo(Plane.WorldXY.Origin) > 0)
      {
        Curve upperArc = crvs[i];
        A = upperArc;
      }
    }

file:arcSide.gh (3.3 KB)

A distance between points is positive. You use Plane.WorldXY.DistanceTo() or do if(midPt.Z > 0).

Also instead your sphere/plane intersection you can just use Circle.TryFitCircleToPoints

Hi Dani,

thanks a lot!

Thanks Michael,

unfortunatly its not available in the version they use here,

I’ve implemented a “FitSphere” - component once. Its based on simple Least Square Regression.
You can take this algorithm and make it 2D. It will be the same as TryFitCircleToPoints then. Just make sure to feed in Points sharing one plane, and instead of creating a sphere object, you take a Circle object instead:

SphereFitLS.gh (14.6 KB)

1 Like

actually, its super simple to convert this script:
CircleFitLS.gh (4.1 KB)

FitCircle

1 Like

Hi @TomTom,

thanks, its very interessting.
For me the sphereIntersect thing is easier to understand.
Yours is that kind of that scripts I save and study but I never would have reached to this kind of solution.

Regards!