Does using a 2 or 4 point create surface method affect the code?

The script, which is written in C# does not work when I use a 4 point create surface method. However, when I create the exact same surfaces with a 2 point surface create method it does work… I don’t quite understand why. I am using Rhino WIP on windows.

Here is the script:

  private void RunScript(Surface srfA, Surface srfB, double radius, double tol, ref object A)
  {
    //Declare an array of surfaces
    Surface[] surfaces = {};

    //Check for a valid input
    if (srfA != null && srfB != null)
    {
      //Create fillet surfaces
      surfaces = Surface.CreateRollingBallFillet(srfA, srfB, radius, tol);
    }

    A = surfaces;
  }

I am using the exact same components, and script:

The GH file:Srf_Drawing_Bug.gh (21.7 KB)

1 Like

@DavidLeon
Can you please help? :thinking: :pray:

The main difference is in your surface UV directions, It’s not about what command you’re using, it’s about how you are using these command to make the surface.
You can reverse these directions like this:

private void RunScript(Surface srf, bool u, bool v, ref object A)
{
  if (u)
    srf.Reverse(0, true);
  if (v)
    srf.Reverse(1, true);
  A = srf;
}


RollingBallFillet.gh (16.9 KB)

1 Like

You can use another overload of CreateRollingBallFillet.

private void RunScript(Surface srfA, Surface srfB, double radius, double tol, ref object A)
{
  if (srfA != null && srfB != null)
  {
    var pA = new Point2d(srfA.Domain(0).Mid, srfA.Domain(1).Mid);
    var pB = new Point2d(srfB.Domain(0).Mid, srfB.Domain(1).Mid);
    A = Surface.CreateRollingBallFillet(srfA, pA, srfB, pB, radius, tol);
  }
}

RollingBallFilletOverload.gh (11.1 KB)

2 Likes

Arrange 2 planar surfaces like an Extruded x. Now it can create 4 valid fillets. Which fillet is the required one? Both uv point hints which fillet is the required one. I wouldn‘t pick the domain mid for this, but instead two uv points indicating the correct side. You can also create a point in space and find both surfaces closest point and use these uv points for this. But assuming surfaces are always arranged like (Extruded L) this it will work of course

private void RunScript(Surface srfA, Point3d ptA, Surface srfB, Point3d ptB, double radius, double tol, ref object fillets)
{
  if (srfA != null && srfB != null)
  {
    var pointA = new Point2d(srfA.Domain(0).ParameterAt(ptA.X), srfB.Domain(1).ParameterAt(ptA.Y));
    var pointB = new Point2d(srfA.Domain(0).ParameterAt(ptB.X), srfB.Domain(1).ParameterAt(ptB.Y));
    fillets = Surface.CreateRollingBallFillet(srfA, pointA, srfB, pointB, radius, tol);
  }
}

RollingBallFilletOverload_UVPoints.gh (16.5 KB)

private void RunScript(Surface srfA, Surface srfB, Point3d point, double radius, double tol, ref object fillets)
{
  if (srfA != null && srfB != null)
  {
    double uA, vA , uB, vB;
    srfA.ClosestPoint(point, out uA, out vA);
    srfB.ClosestPoint(point, out uB, out vB);

    // Juggle the pickpoint ever so slightly towards the middle of the domain
    // to get a better chance of getting a valid chord.
    if (uB == srfB.Domain(0).Min || uB == srfB.Domain(0).Max)
      uB = 0.99 * uA + 0.01 * srfB.Domain(0).Mid;
    if (vB == srfB.Domain(1).Min || vB == srfB.Domain(1).Max)
      vB = 0.99 * vA + 0.01 * srfB.Domain(1).Mid;

    fillets = Surface.CreateRollingBallFillet(srfA, new Point2d(uA, vA), srfB, new Point2d(uB, vB), radius, tol);
  }
}


RollingBallFilletOverload_ClosestPoint.gh (12.7 KB)

3 Likes

@Mahdiyar
Thank you very much for all the codes you gave! The easiest of all, in my opinion, and the most compact is your second code (RollingBallFilletOverload).
I have a question regarding this, when defining pointA you take the mid-point of the domain of surface a, then the mid-point of the domain of surface b. However, when defining pointB, you take the mid-point of the domain of surface b, and then again take the midpoint of domain of surface b.
So, my question is why not surface b, and then surface a, as it also works, but why?

P.S. I really liked the way you organized your posts,and the way you explained them as it helped see what each code does.

This was a mistake, I’ve just edited my post.

Thanks, now it makes more sense!