algorithmic modeling for Rhino
Hi to all,
I doing a C# component to trim automatically pipes that self-intersect. I want to trim pipes like this:
I use for this Brep.Trim Method (Brep, Double). On developer.rhino3d.com is explained that "If the Cutter is closed, then a connected component of the Brep that does not intersect the cutter is kept if and only if it is contained in the inside of cutter.", so I obtain as a result of the trimming only the inner part of the pipe (yellow one in the above image). Instead I want the outer part (the black arrow).
How can I obtain only the outer part? Can you give some tips, some ideas?
Thanks
here my simple test code:
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddBrepParameter("Brep", "Brep", "Brep to trim", GH_ParamAccess.item);
pManager.AddBrepParameter("Cutter", "Cutter", "Brep Cutter", GH_ParamAccess.item);
//AddIntegerParameter
}
/// <summary>
/// Registers all the output parameters for this component.
/// </summary>
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddSurfaceParameter("Cut Surface", "CS", "Cut Brep", GH_ParamAccess.list);
pManager.AddBrepParameter("Cut Brep", "CB", "Cut Brep", GH_ParamAccess.list);
}
/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
Brep myBrep = new Brep();
Brep myCutter = new Brep();
DA.GetData(0, ref myBrep);
DA.GetData(1, ref myCutter);
Brep[] brepArray = myBrep.Trim(myCutter, 0.1);
List<Surface> surfList = new List<Surface>();
List<Brep> brepList = new List<Brep>();
for (int i = 0; i < brepArray.Length; i++)
{
brepList.Add(brepArray[i]);
int num = brepArray[i].Surfaces.Count;
if (brepArray[i].Surfaces.Count > 0)
{
for (int r = 0; r < brepArray[i].Surfaces.Count; r++)
{
surfList.Add(brepArray[i].Surfaces[r]);
}
}
}
DA.SetDataList(0, surfList);
DA.SetDataList(1, brepList);
}
Tags:
1. Don't do this:
Brep myBrep = new Brep();
Brep myCutter = new Brep();
There's no point making a new Brep if you're about to overwrite it. Just say Brep myBrep = null;
You're going to have to use Split() instead of Trim(), and then figure out which of the remaining pieces is unwanted.
Hi Robert,
well you cannot find it "automatically" since the index of the newly generated trimmed surfaced depends on many factors.
I usually a check that has to do with are or inclusion within the bounding box of the second pipe.
the latter works better but your bounding box needs to be aligned to the main axis of the pipe.
Hope this makes sense.
Ta,
M
no problem,
Btw, what I wanted to type above was area and not "are".
The inclusion should work fine, but might not be bulletproof depending on the size of your pipes.
Best,
M
You can also use the BoundingBox of each split segment, find the centre and test that for inclusion inside the splitter pipe object.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by