<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Breaking all curves at intersections and storing those points in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9796687#M18290</link>
    <description>&lt;P&gt;Awesome, thanks for pointing me in the right direction. I will update the OP when I have cleaned it up a bit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had to go with Point2dCollection instead of DoubleCollection because the points kept being off after the curves had been split.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The preliminary boundblock check is a great idea too, thanks for that as well!&lt;/P&gt;</description>
    <pubDate>Sun, 11 Oct 2020 20:57:53 GMT</pubDate>
    <dc:creator>ManiTraf</dc:creator>
    <dc:date>2020-10-11T20:57:53Z</dc:date>
    <item>
      <title>Breaking all curves at intersections and storing those points</title>
      <link>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9796199#M18286</link>
      <description>&lt;P&gt;Hello there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a shortest path function based of polylines, lines and arcs. The actual pathfinding won't be the problem, finding the intersections doesn't look like a problem either. My problem is that I can't figure out how to split the curve2ds after an intersection and make sure the loop continues correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list&amp;lt;curve2d&amp;gt; which consists of either circulararc2d or linesegment2d objects. I want to run a double for loop, so everything get's checked against everything. Easy, now I can't figure out what to do when there is an intersection, and the curve2d should be split. Do I remove the current curve from the list and add the new 2 curves( obviously only if the intersection doesn't happen at the start or end). I'm pretty sure that messes up the indexing too. I have tried messing with the i and j values, but it kept missing intersections after some curve had interesected another. Am I overlooking something simple or do I need your brilliant minds?&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 11:52:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9796199#M18286</guid>
      <dc:creator>ManiTraf</dc:creator>
      <dc:date>2020-10-11T11:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: Breaking all curves at intersections and storing those points</title>
      <link>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9796270#M18287</link>
      <description>&lt;P&gt;Have you looked into Curve2d[Curve3d, Curve].GetSplitCurves() method?&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 13:24:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9796270#M18287</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2020-10-11T13:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Breaking all curves at intersections and storing those points</title>
      <link>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9796283#M18288</link>
      <description>&lt;P&gt;Yes, my problem is mainly what to do with the lines it returns. Right now I replace the current line for one of the added lines and add the last one. But it's still not working out great with lines with more than 1 intersection.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;for (int i = 0; i &amp;lt; curve2Ds.Count - 1; i++)
            {
                var curve_i = curve2Ds[i];
                for (int j = i + 1; j &amp;lt; curve2Ds.Count; j++)
                {
                    var curve_j = curve2Ds[j];
                    try
                    {
                        CurveCurveIntersector2d curveCurveIntersector = new CurveCurveIntersector2d(curve_i, curve_j);

                        if (curveCurveIntersector.NumberOfIntersectionPoints &amp;gt; 1)
                        {
                            
                            for (int k = 0; k &amp;lt; curveCurveIntersector.NumberOfIntersectionPoints; k++)
                            {
                                var p = (PointModel)Storage.storage.Points.GetOrAdd(curveCurveIntersector.GetIntersectionPoint(k));
                                p.SetIdMessage("ERROR: " + k);
                                return;
                            }
                        }
                        else if (curveCurveIntersector.NumberOfIntersectionPoints &amp;gt; 0)
                        {
                            var point = curveCurveIntersector.GetIntersectionPoint(0);
                            PointModel node = (PointModel)Storage.storage.Points.GetOrAdd(point);

                            var intersection = curveCurveIntersector.GetIntersectionParameters(0);

                            var curve = curve_i;
                            Check if intersection is on the edge or not
                            if (!curve.StartPoint.Equals(point) &amp;amp;&amp;amp; !curve.EndPoint.Equals(point))
                            {
                                var startNode = (PointModel)Storage.storage.Points.GetOrAdd(curve.StartPoint);
                                var endNode = (PointModel)Storage.storage.Points.GetOrAdd(curve.EndPoint);
                                var curves = curve.GetSplitCurves(intersection[0]).ToList();

                                curve_i = curves[0];
                                curve2Ds.Add(curves[1]);

                                startNode.ReplaceConnection(node, endNode, curves[0]);
                                endNode.ReplaceConnection(node, startNode, curves[1]);
                            }

                            curve = curve_j;

                            if (!curve_j.StartPoint.Equals(point) &amp;amp;&amp;amp; !curve_j.EndPoint.Equals(point))
                            {
                                var startNode = (PointModel)Storage.storage.Points.GetOrAdd(curve.StartPoint);
                                var endNode = (PointModel)Storage.storage.Points.GetOrAdd(curve.EndPoint);
                                var curves = curve.GetSplitCurves(intersection[1]).ToList();

                                curve_j = curves[0];
                                curve2Ds.Add(curves[1]);

                                startNode.ReplaceConnection(node, endNode, curves[0]);
                                endNode.ReplaceConnection(node, startNode, curves[1]);
                            }

                        }
                        Storage.storage.Curves.Clear();
                        Storage.storage.Curves.AddRange(curve2Ds);
                    }
                    catch (Autodesk.AutoCAD.Runtime.Exception ex)
                    {
                        ed.WriteMessage("\n Error in FindIntersections Loop \n{0},\n {1}", ex.Message, ex.StackTrace);
                    }
                }

            }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 13:35:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9796283#M18288</guid>
      <dc:creator>ManiTraf</dc:creator>
      <dc:date>2020-10-11T13:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Breaking all curves at intersections and storing those points</title>
      <link>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9796385#M18289</link>
      <description>&lt;P&gt;It looks like you are close to what you need but, as another variation on looping:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Prepare double loop&lt;/P&gt;&lt;P&gt;Perhaps use BoundBlock2d.IsDisjoint as preliminary test&lt;/P&gt;&lt;P&gt;If not Disjointed&lt;/P&gt;&lt;P&gt;Record the parameter of the intersection in a Dictionary&amp;lt;int, DoubleCollection&amp;gt;.&lt;/P&gt;&lt;P&gt;i.e., Curve2dCollection remains unchanged&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then Loop yet again coordinating the original Curve2ds with the intersection parameters to split each Curve.&lt;/P&gt;&lt;P&gt;Quite possibly there will be more than one – perhaps even several – &amp;nbsp;intersections.&amp;nbsp; It may make sense to sort the DoubleCollection parameter values to help coordinate splitting the various remnants.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 15:21:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9796385#M18289</guid>
      <dc:creator>SEANT61</dc:creator>
      <dc:date>2020-10-11T15:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Breaking all curves at intersections and storing those points</title>
      <link>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9796687#M18290</link>
      <description>&lt;P&gt;Awesome, thanks for pointing me in the right direction. I will update the OP when I have cleaned it up a bit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had to go with Point2dCollection instead of DoubleCollection because the points kept being off after the curves had been split.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The preliminary boundblock check is a great idea too, thanks for that as well!&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 20:57:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9796687#M18290</guid>
      <dc:creator>ManiTraf</dc:creator>
      <dc:date>2020-10-11T20:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: Breaking all curves at intersections and storing those points</title>
      <link>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9797239#M18291</link>
      <description>&lt;P&gt;Here is the full solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;// List curve2Ds consists of LineSegment2d &amp;amp; CircularArc2d, NOTHING ELSE!
        public void FindIntersections(List&amp;lt;Curve2d&amp;gt; curve2Ds)
        {
            var intersections = new Dictionary&amp;lt;int, Point2dCollection&amp;gt;();

            for (int i =0; i &amp;lt; curve2Ds.Count -1; i++)
            {
                var curve_i = curve2Ds[i];
                if (!intersections.ContainsKey(i))
                {
                    intersections.Add(i, new Point2dCollection());
                }
                
                for (int j = i+1; j &amp;lt; curve2Ds.Count; j++)
                {
                    var curve_j = curve2Ds[j];
                    if (!intersections.ContainsKey(j))
                    {
                        intersections.Add(j, new Point2dCollection());
                    }

                    if (!curve_i.BoundBlock.IsDisjoint(curve_j.BoundBlock))
                    {
                        var curveCurveIntersector = new CurveCurveIntersector2d(curve_i, curve_j);
                        if (curveCurveIntersector.NumberOfIntersectionPoints &amp;gt; 1)
                        {
                            for (int k = 0; k &amp;lt; curveCurveIntersector.NumberOfIntersectionPoints; k++)
                            {
                                Func&amp;lt;PointModel&amp;gt; fun = delegate ()
                                {
                                    return new PointModel(curveCurveIntersector.GetIntersectionPoint(k), Storage.storage.Points.GetUnusedId());
                                };
                                var p = (PointModel)Storage.storage.Points.GetOrAdd(curveCurveIntersector.GetIntersectionPoint(k), fun);
                                p.SetIdMessage("ERROR: " + k);
                                return;
                            }
                        }

                        else if (curveCurveIntersector.NumberOfIntersectionPoints &amp;gt; 0)
                        {
                            var intersectionPoint = curveCurveIntersector.GetIntersectionPoint(0);

                            if (!curve_i.StartPoint.Equals(intersectionPoint) &amp;amp;&amp;amp; !curve_i.EndPoint.Equals(intersectionPoint))
                            {
                                var param = curve_i.GetParameterOf(intersectionPoint);
                                if (!intersections[i].Contains(intersectionPoint))
                                {
                                    intersections[i].Add(intersectionPoint);
                                }
                            }

                            if (!curve_j.StartPoint.Equals(intersectionPoint) &amp;amp;&amp;amp; !curve_j.EndPoint.Equals(intersectionPoint))
                            {
                                var param = curve_j.GetParameterOf(intersectionPoint);
                                if (!intersections[j].Contains(intersectionPoint))
                                {
                                    intersections[j].Add(intersectionPoint);
                                }
                            }
                        }
                    }
                }
            }
            // Split all curves at intersections and add them to a new list

            var curves = new List&amp;lt;Curve2d&amp;gt;();

            PointModel startPointModel = null;
            PointModel endPointModel = null;

            for (int i = 0; i &amp;lt; curve2Ds.Count; i++)
            {
                var curve = curve2Ds[i];
                var intersects = intersections[i].ToArray();
                var sortedIntersects = intersects.OrderBy(p =&amp;gt; curve.GetParameterOf(p));

                Point2d point = new Point2d();
                Func&amp;lt;PointModel&amp;gt; func = delegate ()
                {
                    return new PointModel(point, Storage.storage.Points.GetUnusedId());
                };

                ed.WriteMessage("\n Intersections for {0} are {1}", i, intersections[i].Count);
                foreach (var p in sortedIntersects)
                {
                    var param = curve.GetParameterOf(p);
                    var splitCurves = curve.GetSplitCurves(param);
                    ed.WriteMessage("\n Double d = {0}, splitcount = {1}", param, splitCurves.Length); ;
                    curves.Add(splitCurves[0]);

                    point = splitCurves[0].StartPoint;
                    startPointModel = (PointModel)Storage.storage.Points.GetOrAdd(point, func);

                    point = splitCurves[0].EndPoint;
                    endPointModel = (PointModel)Storage.storage.Points.GetOrAdd(point, func);

                    startPointModel.AddConnection(endPointModel, splitCurves[0]);
                    endPointModel.AddConnection(startPointModel, splitCurves[0]);

                    curve = splitCurves[1];


                };
                // Add the last part of the line, or if no intersections found the whole line.
                point = curve.StartPoint;
                startPointModel = (PointModel)Storage.storage.Points.GetOrAdd(point, func);

                point = curve.EndPoint;
                endPointModel = (PointModel)Storage.storage.Points.GetOrAdd(point, func);

                startPointModel.AddConnection(endPointModel, curve);
                endPointModel.AddConnection(startPointModel, curve);
                curves.Add(curve);
            }

            ed.WriteMessage("\n From {0} curves to {1}", curve2Ds.Count,curves.Count);

            
            
        }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 08:21:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9797239#M18291</guid>
      <dc:creator>ManiTraf</dc:creator>
      <dc:date>2020-10-12T08:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: Breaking all curves at intersections and storing those points</title>
      <link>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9799316#M18292</link>
      <description>&lt;P&gt;Kudos.&amp;nbsp; I can appreciate the effort to make an inherently complex procedure possible.&amp;nbsp;&amp;nbsp;Nicely done.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 07:14:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/9799316#M18292</guid>
      <dc:creator>SEANT61</dc:creator>
      <dc:date>2020-10-13T07:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: Breaking all curves at intersections and storing those points</title>
      <link>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/12041214#M18293</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6684065"&gt;@ManiTraf&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the code, is "Storage" is "&lt;SPAN&gt;Azure Storage"?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What is the minimum implementation of "PointModel" so that the function can be compiled?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In my case I want to take a collection of curves, break them at all intersection points, use REGION creation from all the curves and then create all the polygons.&lt;BR /&gt;(Something similar to MAPCLEAN and creating a polygonal topology)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Jun 2023 20:07:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/12041214#M18293</guid>
      <dc:creator>Izhar_Azati</dc:creator>
      <dc:date>2023-06-17T20:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: Breaking all curves at intersections and storing those points</title>
      <link>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/12043096#M18294</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's been a while and I've changed things since, but Storage was just a class where I would share lists ands dicts in.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The collectionmodels are dictionaries with &amp;lt;T, id&amp;gt; and some helper functions for that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the pointmodel only has&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;public Point3d Position &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would advise you to use the steps in the code to convert the list of curves into a list of all broken curves, your application for this seems different than mine was and I think you don't need as much code as I did&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2023 05:33:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/breaking-all-curves-at-intersections-and-storing-those-points/m-p/12043096#M18294</guid>
      <dc:creator>ManiTraf</dc:creator>
      <dc:date>2023-06-19T05:33:27Z</dc:date>
    </item>
  </channel>
</rss>

