Hello,

I’m trying to flatten a 3d shape. The 3d shape is a brace intended to fit a patient’s leg. I want to cut some foam to protect the leg from the brace.

In Solidworks, I create an offset surface 3mm from the brace, then I flatten, giving a seam right in the middle of the brace. The result is always accurate.

I’m trying to perform the same steps in Rhino but the result is quite different (blue: Solidworks).

The 3mm offset works fine.

`toFlatten = Brep.CreateOffsetBrep(originalBrep, PluginModel.Instance.IsLeftLeg ? offsetInward : -offsetInward, false, false, tolerance, out _, out _).FirstOrDefault();`

result_solidworks.DXF (84.0 KB)

sagittalPlane.dxf (158.9 KB)

squished.dxf (546.2 KB)

originalBrep.dxf (281.5 KB)

rhino settings.txt (2.5 KB)

Cutting with a vertical plane works fine:

`var splitBreps = SplitBrepWithPlane(toFlatten, sagittalPlane, PluginConstant.Tolerance);`

where

```
public static Brep[] SplitBrepWithPlane(Brep brep, Plane plane, double tolerance)
{
var bbox = brep.GetBoundingBox(false);
//Grow the boundingbox in all directions
//If the boundingbox is flat (zero volume or even zero area)
//then the CreateThroughBox method will fail.
var min_point = bbox.Min;
min_point.X -= 1.0;
min_point.Y -= 1.0;
min_point.Z -= 1.0;
bbox.Min = min_point;
var max_point = bbox.Max;
max_point.X += 1.0;
max_point.Y += 1.0;
max_point.Z += 1.0;
bbox.Max = max_point;
var plane_surface = PlaneSurface.CreateThroughBox(plane, bbox);
return brep.Split(plane_surface.ToBrep(), tolerance);
}
```

However, flattening each part individually is inaccurate:

```
foreach (var splitBrep in splitBreps)
{
var toSquish = CreateMeshFromBrep(splitBrep, MeshingParameters.QualityRenderMesh);
SquishParameters squishparams = new SquishParameters();
squishparams.Algorithm = SquishFlatteningAlgorithm.Geometric; // also tried PhysicalStress
// tried default + various other parameters. Solidworks seemed to have a strong bias to preserving boundary lengths at the expense of interior distortion, and no preference between compression and stretching
squishparams.SetSpringConstants(boundaryBias: 1.0, deformationBias: 0.0);
Rhino.Geometry.Squisher squisher = new Squisher();
// actually squish the mesh
Mesh squished = squisher.SquishMesh(squishparams, toSquish, geometryToFollow, squishedGeometryToFollow);
// then some logic to stitch the parts together
```

where

```
public static Mesh CreateMeshFromBrep(Brep brep, MeshingParameters method)
{
var meshes = Mesh.CreateFromBrep(brep, method);
if (meshes == null || meshes.Length == 0)
return null;
var result = new Mesh();
foreach (var mesh in meshes)
result.Append(mesh);
return result;
}
```

Stitching: Solidworks seemed to keep the beginning of the curve (boundary between the 2 meshes = intersection of plane with toFlatten).

I’m doing a best fit on 10 points at the beginning of the curve (first third), it seems to work fine.

Do you have any suggestions to get a result that matches the result by Solidworks?

I’ve tried to use an Unroller, a Squisher, each with many parameters, with and without the seam in the middle, and I’m running out of options.

Thanks!