.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Point inside a closed figure

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
530 Views, 9 Replies

Point inside a closed figure

Is there a function that will determine whether or not a point resides within a closed figure (i.e. polyline, circle, etc.)?

This should be so easy, but I'm missing it.

Thanks,

Richard Olson
9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: Anonymous

radioflyer651 wrote:

> Is there a function that will determine whether or not a point resides within a
> closed figure (i.e. polyline, circle, etc.)? This should be so easy, but I'm
> missing it. Thanks, Richard Olson

If you need to create your own:
http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/

Terry
Message 3 of 10
Anonymous
in reply to: Anonymous


>>>This should be so easy

 

 

Look into the MPolygon
class.
Message 4 of 10
Indu.Shukla
in reply to: Anonymous

How can I cast an entity to MPolygon?

Message 5 of 10
_gile
in reply to: Indu.Shukla


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.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 6 of 10
Indu.Shukla
in reply to: _gile

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?Mpolygon.PNG

Message 7 of 10
_gile
in reply to: Indu.Shukla

Perhaps a problem with the polyline you're using (self intersecting).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 8 of 10
kacarikalen
in reply to: Indu.Shukla

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.

 

 

Geodetic specialist
Message 9 of 10
JamesMaeding
in reply to: Anonymous

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

Message 10 of 10
JamesMaeding
in reply to: kacarikalen

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost