turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Close

.NET

- Autodesk Community
- >
- AutoCAD Customization
- >
- .NET
- >
- Re: Point on polygon

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

400 Views, 4 Replies

07-30-2013 04:34 AM

Hi,

I want to check if a point lies inside a polygon and i also want to check if that particular point lies on the polygon.

Thanks

Gulzar

Solved! Go to Solution.

Solved! by dynamicscope. See the answer in context.

Oh, didn't know you also wanted to check if the point is on polygon.

I guess you can just check that with the linear equation of every side of the polygon.

Or you can use GetDistAtPoint(Point3d point) method of the Curve entity.

It throws an InvalidInput Exception if the point is not on the curve entity.

I guess you can just check that with the linear equation of every side of the polygon.

Or you can use GetDistAtPoint(Point3d point) method of the Curve entity.

It throws an InvalidInput Exception if the point is not on the curve entity.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-30-2013 05:40 AM in reply to:
gulzar25

Below 2 links might be a help for you:

http://www.theswamp.org/index.php?topic=44576.0

http://www.theswamp.org/index.php?PHPSESSID=6270mh06mh8jjj3rt6mbuhmkk1&topic=43572.msg488632#msg4886...

http://www.theswamp.org/index.php?topic=44576.0

http://www.theswamp.org/index.php?PHPSESSID=6270mh

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-30-2013 07:38 PM in reply to:
gulzar25

I use the following algorithm. Try this.

public struct Point { public double x; public double y; public Point(double _x, double _y) { x = _x; y = _y; } } // wn_PnPoly(): winding number test for a point in a polygon // Input: P = a point, // V[] = vertex points of a polygon V[n+1] with V[n]=V[0] // Return: wn = the winding number (=0 only if P is outside V[]) public static bool IsInPolygon(Point[] V, Point P, int n) { int wn = 0; // the winding number counter // loop through all edges of the polygon for (int i = 0; i < n; i++) { // edge from V[i] to V[i+1] if (V[i].y <= P.y) { // start y <= P.y if (V[i + 1].y > P.y) // an upward crossing if (isLeft(V[i], V[i + 1], P) > 0) // P left of edge ++wn; // have a valid up intersect } else { // start y > P.y (no test needed) if (V[i + 1].y <= P.y) // a downward crossing if (isLeft(V[i], V[i + 1], P) < 0) // P right of edge --wn; // have a valid down intersect } } if (wn == 0) return false; else return true; } // isLeft(): tests if a point is Left|On|Right of an infinite line. // Input: three points P0, P1, and P2 // Return: >0 for P2 left of the line through P0 and P1 // =0 for P2 on the line // <0 for P2 right of the line // See: the January 2001 Algorithm "Area of 2D and 3D Triangles and Polygons" internal static double isLeft( Point P0, Point P1, Point P2 ) { return ( (P1.x - P0.x) * (P2.y - P0.y) - (P2.x - P0.x) * (P1.y - P0.y) ); }

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-30-2013 10:51 PM in reply to:
gulzar25

Hi,

Thanks for the reply.

I tried using the above code but it gives same results for point on polygon and for point inside polygon.Is there any way to differentiate.

Thanks

Gulzar

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

07-31-2013 12:38 AM in reply to:
gulzar25

I guess you can just check that with the linear equation of every side of the polygon.

Or you can use GetDistAtPoint(Point3d point) method of the Curve entity.

It throws an InvalidInput Exception if the point is not on the curve entity.

Search This Board

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Post to the Community

Have questions about Autodesk products? Ask the community.

The Knowledge Network

Access a broad range of knowledge to help get the most out of your products and services.

Download & Installation

Getting your Software

Downloads & Upgrades

Serial Numbers & Product Keys

Installation & Licensing

Activation & Registration

Network License Administration

Subscription Management

Sign In / Create Account

Maintenance Subscription Help

Desktop Subscription Help

Cloud Service Subscription FAQ

Announcements

Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the *Autodesk Help | Learn | Collaborate* booths in the Exhibit Hall and meet our community team if you get a chance!

- Privacy | Legal Notices & Trademarks | Report Noncompliance | Site map | © Copyright 2014 Autodesk Inc. All rights reserved

Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Please see the Autodesk Creative Commons FAQ for more information.