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

unhandled

#1

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)


#2

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


(Michael Pryor) #3

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


#4

Hi Dani,

thanks a lot!


#5

Thanks Michael,

unfortunatly its not available in the version they use here,


(Tom) #6

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)


(Tom) #7

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

FitCircle


#8

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!