i try to make appliction (plugin) in c# code to work as superboundary or FlashPolygons
I need help in this
I tried many ways but the result not good
Region.CreateFromCurves(curves); not good
https://superboundary.com/download.html
https://www.delicad.com/en/flashpolygons.php
If any one have the ability, send me a private message so we can agree on a price
Hi,
Give a try to the following MergeCurves method.
struct Segment
{
public Point2d StartPt { get; set; }
public Point2d EndPt { get; set; }
public double Bulge { get; set; }
}
private static IEnumerable<Polyline> MergeCurves(IEnumerable<Curve> curves)
{
var splitCurves = new List<Curve>();
var curveSegments = new DBObjectCollection();
foreach (Curve curve in curves)
{
if (curve is Arc || curve is Circle || curve is Line || curve is Polyline)
{
foreach (Curve c in GetSplitSegments(curve, curves))
{
splitCurves.Add(c);
curveSegments.Add(c);
}
}
}
var regions = Region.CreateFromCurves(curveSegments);
foreach (Curve c in splitCurves)
{
c.Dispose();
}
if (regions.Count == 0) yield break;
Region region = (Region)regions[0];
for (int i = 1; i < regions.Count; i++)
{
region.BooleanOperation(BooleanOperationType.BoolUnite, (Region)regions[i]);
regions[i].Dispose();
}
var entitySet = new DBObjectCollection();
region.Explode(entitySet);
region.Dispose();
var segments = new List<Segment>();
var plane = new Plane(Point3d.Origin, Vector3d.ZAxis);
while (entitySet.Count > 0)
{
if (entitySet[0] is Region r)
{
r.Explode(entitySet);
continue;
}
Curve curve = (Curve)entitySet[0];
Point3d start = curve.StartPoint;
Point3d end = curve.EndPoint;
double bulge = 0.0;
if (curve is Arc arc)
{
double angle = arc.Center.GetVectorTo(start).GetAngleTo(arc.Center.GetVectorTo(end), arc.Normal);
bulge = Math.Tan(angle / 4.0);
}
segments.Add(new Segment { StartPt = start.Convert2d(plane), EndPt = end.Convert2d(plane), Bulge = bulge });
entitySet[0].Dispose();
entitySet.RemoveAt(0);
}
while (segments.Count > 0)
{
var pline = new Polyline();
pline.AddVertexAt(0, segments[0].StartPt, segments[0].Bulge, 0.0, 0.0);
Point2d pt = segments[0].EndPt;
segments.RemoveAt(0);
int vtx = 1;
while (true)
{
int i = segments.FindIndex((s) => s.StartPt.IsEqualTo(pt) || s.EndPt.IsEqualTo(pt));
if (i < 0) break;
Segment seg = segments[i];
if (seg.EndPt.IsEqualTo(pt))
seg = new Segment { StartPt = seg.EndPt, EndPt = seg.StartPt, Bulge = -seg.Bulge };
pline.AddVertexAt(vtx, seg.StartPt, seg.Bulge, 0.0, 0.0);
pt = seg.EndPt;
segments.RemoveAt(i);
vtx++;
}
pline.Closed = true;
yield return pline;
}
}
private static DBObjectCollection GetSplitSegments(Curve curve, IEnumerable<Curve> curves)
{
var points = new Point3dCollection();
foreach (var c in curves)
{
curve.IntersectWith(c, Intersect.OnBothOperands, points, IntPtr.Zero, IntPtr.Zero);
}
if (points.Count == 0) return new DBObjectCollection { (Curve)curve.Clone() };
var parameters = points
.Cast<Point3d>()
.Select(p => curve.GetParameterAtPoint(p))
.OrderBy(p => p)
.ToArray();
return curve.GetSplitCurves(new DoubleCollection(parameters));
}
THANK YOU FOR REPLY
I tried this before it is so weak
when you have not closed polygon or polyline it gives an error
so you start to check every polyline (sometimes more than 1000)
and if the area of polygon is small it will not give it
Region.CreateFromCurves(curveSegments); not good for this type of works
In AutoCAD MAP you have: MAPCLEAN
https://help.autodesk.com/view/MAP/2024/ENU/?guid=GUID-F0A6B62A-03BF-4839-BA51-A6E703049326
And there are other libraries that actually build a topology.
In the files we come across inaccuracies in the coordinates, roughly overlapping lines that in the real world have no importance at all.
Arches are often untreated. 3D information is often not saved.
Can't find what you're looking for? Ask the community or share your knowledge.