Issue with Surface projection onto another Surface

Hi!

I am having some issues projecting a surface (sufaceA), which is not a perfect rectangle, but planar, onto another surface (surfaceB). My approach is to take the boundary curves from the surfaceA and the basePlane from surfaceB and use Curve.ProjectToPlane. Then i use those curves to Brep.CreatePlanarBreps with the RhinoTolerance set to 0.000001.

My problem is, that the projected surfaceA seems to be corrected sometimes, why and where?
For example I use a surfaceA, project it - works perfectly and the area is still the same
Then i use the same surfaceA that was just projected, move it a bit and project it again, and the result is a perfect rectangle with a different area.

Any hints would be great, i have this encapsulated into a try method within a command:

                var targetSurfaceBrep = targetSurface.ToBrep();

                var surfaceBoundaryCurves = targetSurfaceBrep.DuplicateNakedEdgeCurves(true, false);
                if (surfaceBoundaryCurves == null || surfaceBoundaryCurves.Length == 0)
                {
                    return false;
                }

                var projectedCurves = surfaceBoundaryCurves
                    .Select(curve => Curve.ProjectToPlane(curve, basePlane))
                    .Where(projectedCurve => projectedCurve != null)
                    .ToList();

                if (projectedCurves.Count == 0)
                {
                    return false;
                }

                var projectedSurface = Brep.CreatePlanarBreps(projectedCurves, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)?.FirstOrDefault();
                if (projectedSurface == null)
                {
                    return false;
                }

                var polyline = new Polyline(projectedSurface.Vertices.Select(v => v.Location));
                if (!polyline.IsClosed) polyline.Add(polyline[0]);

                var polylineCurve = polyline.ToNurbsCurve();
                if (polylineCurve == null)
                {
                    return false;
                }

                var targetObject = RhinoDoc.ActiveDoc.Objects.Find(targetSurfaceObjRef.ObjectId);
                if (targetObject == null)
                {
                    return false;
                }

                RhinoDoc.ActiveDoc.Objects.Delete(targetSurfaceObjRef, true);
                return true;

Hi @Benterich,

You might want to post a .3dm file that contains your source and target surfaces.

– Dale

No need, i found the solution!

When I got the surface object references, i stored the targetSurface as a:
targetSurface = surfaceObjRef.Surface();

Hence when using untrimmed surfaces, it adusted it. The solution is to use a brepFace, hence:
var brepFace = surfaceObjRef.Face();