Indu.Shukla a écrit :
How can I cast an entity to MPolygon?
You can create a new instance of MPolygon and use the AppendLoopFromBoundary() method which accepts Polyline, Polyline2d and Circle entities as first argument.
See my first reply in this thread.
Thanks _gile for your reply.
I did try this also but I am getting exception error "eValidInput". My code is crashing on mpg.AppendLoopFromBoundary(pline, true, tolerance);
See the values in the screenshot, is it because of tolerance value?
Hello,
You can do it programmatically. First calculate the area of polygon, you can read its closed polyline area property. then get boundary vertices, calculate triangle area by iterating every time through 2 boundary vertices and your point.
After you sum up your triangle areas it should be like the area from boundary + - rounding error.
If your summed area from triangles is way much greater than tolerance then your point is outside of the polygon.
See the picture i attached, hope that helps.
Most solutions I have seen are too slow when checking say 1000 pts against a closed shape with 5000 segments.
You run into that when sampling a grid of points from a surface, or trying to erase stuff inside/outside a shape.
It is not good enough to break arcs into little segs, so the shape can have arcs in it.
The fastest solution I came up with is to make a vert line object, and see where it hits the segs.
If it hits at two points, and you are between, you know you are inside. Same thinking for outside and no/multiple hits.
The trick is to sort the segs by bounding box start x, and another list by bounding end x.
Then you only check for actual intersection on segs that have bounding box overlap with the line.
Reuse the sorted lists on other points, do not sort over and over.
So while line only segments have better approaches, if you have arcs you must do my way.
Its still a bit slow so I am looking for further optimizations.
You need routines to detect line/line and line/arc intersections with this.
I made my own but acad has them too.
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties
that area approach is limited to straight segs.
I think there are "sweep-line" methods that are fastest if you google that.
Kind of depends what you are doing when choosing a junky or rubust solution.
internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties