I'm looking for a way to trim an ellipse. Would trim function work in here? If i open the drawing it is very easy to use trim function, but in .net i'm not to sure.
I am attaching a pic for that.
Thank you for your time.
Alex
Thanks for your reply.
The curves are to ellipses cut by a vertical line. i got the intersection points using IntersectWith function and i created 2 small vertical lines, one on top and one at the bottom. Now next step is to eliminate the left side of the ellipses at the vertical lines. To use trim in actual drawing is quite easy, and i'have been doing this for some time, but to program, i don't know how to do it. I have no code to trim the ellipses. Just code to draw them and to intersect with the vertical line.
Thanks,
Alex
The following code assumes the intersection points (intersPts) have the same X coordinates (vertical line).
private void TrimLeft(Ellipse ellipse, Point3dCollection intersPts, Transaction tr) { var parameters = new DoubleCollection( intersPts.Cast<Point3d>() .Select(p => ellipse.GetParameterAtPoint(p)) .OrderBy(p => p) .ToArray()); var x = intersPts[0].X; var btr = (BlockTableRecord)tr.GetObject(ellipse.OwnerId, OpenMode.ForWrite); foreach (Ellipse item in ellipse.GetSplitCurves(parameters)) { if (item.GetPointAtParameter((item.StartParam + item.EndParam) / 2.0).X < x) { item.Dispose(); } else { btr.AppendEntity(item); tr.AddNewlyCreatedDBObject(item, true); } } if (!ellipse.IsWriteEnabled) ellipse.UpgradeOpen(); ellipse.Erase(); }
Gilles,
Thank you so much for the code. I will implement in vb.net and check it out. I have a spline instead of ellipse. will the code work with spline or do i have to do some transformations first?
Thanks,
Alex
Not tested but it should work with any type derived from Curve.
The line used to get intersection points must be vertical.
private void TrimLeft(Curve curve, Point3dCollection intersPts, Transaction tr) { var parameters = new DoubleCollection( intersPts.Cast<Point3d>() .Select(p => curve.GetParameterAtPoint(p)) .OrderBy(p => p) .ToArray()); var x = intersPts[0].X; var btr = (BlockTableRecord)tr.GetObject(curve.OwnerId, OpenMode.ForWrite); foreach (Curve item in curve.GetSplitCurves(parameters)) { if (item.GetPointAtParameter((item.StartParam + item.EndParam) / 2.0).X < x) { item.Dispose(); } else { btr.AppendEntity(item); tr.AddNewlyCreatedDBObject(item, true); } } if (!curve.IsWriteEnabled) curve.UpgradeOpen(); curve.Erase(); }
Nice LINQ interpretation for sorted points based on the ellips parameters.
You're realy good in LINQ solutions.
Thanks for these samples.
Thanks @SENL1362
I like to use Linq extension methods because I think these (higher order) functions make things simpler and clearer.
This is perhaps due to some functional programming background with LISP and F# (Linq extension methods chaining looks like F# pipe-lining).
If it was not so confidential in AutoCAD .NET programming, I'd like to use more often F#.
let trimLeft (curve: Curve) (pts: Point3dCollection) (tr: Transaction) = let parameters = DoubleCollection(pts |> Seq.cast<Point3d> |> Seq.map(fun p -> curve.GetParameterAtPoint(p)) |> Seq.sort |> Seq.toArray) let x = pts.[0].X let btr = tr.GetObject(curve.OwnerId, OpenMode.ForWrite) :?> BlockTableRecord curve.GetSplitCurves(parameters) |> Seq.cast<Curve> |> Seq.iter(fun c -> if c.GetPointAtParameter((c.StartParam + c.EndParam) / 2.0).X < x then c.Dispose() else btr.AppendEntity(c) |> ignore tr.AddNewlyCreatedDBObject(c, true)) if not curve.IsWriteEnabled then curve.UpgradeOpen() curve.Erase()
I totally agree with you, clean and to the point.
And than only for the Query form so it can be chained (.where().select()...
I am not familiar with F, heard from it and seen it occasionaly in the SWAMP 🙂
Seeing LET gives me flashbacks from the ancient VB times....