Author Topic: Cleanup self-intersecting 3d-plines  (Read 7381 times)

0 Members and 1 Guest are viewing this topic.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2140
  • class keyThumper<T>:ILazy<T>
Re: Cleanup self-intersecting 3d-plines
« Reply #15 on: October 03, 2011, 07:09:46 PM »


Looks like an interesting problem ... sorry I can't make time to play.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Cleanup self-intersecting 3d-plines
« Reply #16 on: October 03, 2011, 07:21:16 PM »
I did not think about closed polylines,
I think throwing in a if statement checking if not at end and closed might fix it up.
 
Got to go hang with kid but will try when I get him asleep
 
 
 

kaefer

  • Guest
Re: Cleanup self-intersecting 3d-plines
« Reply #17 on: October 04, 2011, 03:27:21 AM »
This one is stripped down, and uses IntersectWith

Hi Jeff! (Hi Jeff!)

It's getting interesting by now. They (in their unfathomable wisdom) decided to introduce a version dependancy into the Entity.IntersectWith signature somewhere between the releases 18.0 and 18.2. This little speed bump can be negotiated at runtime, if I'm not completly mistaken, like such:
Code: [Select]
        static Point3dCollection IntersectWith(Entity ent, Entity other)
        {
            Point3dCollection points = new Point3dCollection();
            MethodInfo mi =
                typeof(Entity).GetMember("IntersectWith")
                .Select(mbi => (MethodInfo)mbi)
                .First(mti => mti.GetParameters().Length == 5);
            object arg45 =
                mi.GetParameters()[4].ParameterType == typeof(IntPtr) ? (object)IntPtr.Zero : (object)0;
            object[] args = new object[]{ other, Intersect.OnBothOperands, points, arg45, arg45 };
            mi.Invoke(ent, args);
            return points;
        }

I haven't yet figured out how Jeff H's code works, except that (spoken with lolthulhu): i'm in ur objects mutatin' ur state.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Cleanup self-intersecting 3d-plines
« Reply #18 on: October 04, 2011, 09:39:16 AM »
Yes, that change occurred with 2012, kaefer.  We utilize Conditional Compilation Symbols in our projects which share the same code. So I just needed to do this to work around the change:
Code: [Select]
#if !(C3D2009 || C3D2010 || C3D2011)
                    curve.IntersectWith(intersectingCurve, Intersect.OnBothOperands, points, IntPtr.Zero, IntPtr.Zero);
#else
                    curve.IntersectWith(intersectingCurve, Intersect.OnBothOperands, points, 0, 0);
#endif
It's nice to see other ways to do this.

jmaeding

  • Bull Frog
  • Posts: 304
  • I'm just here for the Shelties.
Re: Cleanup self-intersecting 3d-plines
« Reply #19 on: August 27, 2012, 02:04:32 PM »
this loop trimming is something I ran into a while back.
The solution I found was to create a list of 2d segments (mine handles arcs too), and loop through each segment to see if it hits any others. Record any hits by station and int point.
Then sort the hits by station, and look for items that hit at the same point.
Use that to trim the intersecting segments, plus remove any segments between.
You must decide what the z elevation will be, could be average of endpoints or maybe the first, just choose a method, then add z's back after the 2d analysis.

The trick here is the scaling issue. To make this fast, you must optimize the line-line, line-arc, and arc-arc intersection routines. I do this using bounding box approach, and that even requires optimization.
I cannot share the routines mentioned, but can explain the logic and even the cases to be handled.
The end result is super valuable as you can write your own alignments engine with those ingredients.
James Maeding