Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7971063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:33:19+00:00 2026-06-04T07:33:19+00:00

This question already has an answer here: Point in Polygon aka hit test C#

  • 0

This question already has an answer here:
Point in Polygon aka hit test
C# Point in polygon

Given a random polygon formulated with N line equations in the Cartesian coordinate system, is there any standard formula that is used to check for membership of a point (x,y)?

The simple solution is to get all the line formulas and check if point X is below this line, above that line and to the right of the other line, etc. But this will probably be tedious.

I should note that the polygon can be of any shape with any number of sides and may concave or convex.

For convenience I have already added these utility functions:

float slope(CGPoint p1, CGPoint p2)
{
    return (p2.y - p1.y) / (p2.x - p1.x);
}

CGPoint pointOnLineWithY(CGPoint p, float m, float y)
{
    float x = (y - p.y)/m + p.x;
    return CGPointMake(x,y);
}

CGPoint pointOnLineWithX(CGPoint p, float m, float x)
{
    float y = m*(x - p.x) + p.y;
    return CGPointMake(x, y);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:33:20+00:00Added an answer on June 4, 2026 at 7:33 am

    If you have the vertices, you can compute the sum of the angles made between the test point and each pair of points making up the polygon.
    If it is 2*pi, then it is an interior point. If it is 0, then it is an exterior point.

    Some code:

        typedef struct {
       int h,v;
    } Point;
    
    int InsidePolygon(Point *polygon,int n,Point p)
    {
       int i;
       double angle=0;
       Point p1,p2;
    
       for (i=0;i<n;i++) {
          p1.h = polygon[i].h - p.h;
          p1.v = polygon[i].v - p.v;
          p2.h = polygon[(i+1)%n].h - p.h;
          p2.v = polygon[(i+1)%n].v - p.v;
          angle += Angle2D(p1.h,p1.v,p2.h,p2.v);
       }
    
       if (ABS(angle) < PI)
          return(FALSE);
       else
          return(TRUE);
    }
    
    /*
       Return the angle between two vectors on a plane
       The angle is from vector 1 to vector 2, positive anticlockwise
       The result is between -pi -> pi
    */
    double Angle2D(double x1, double y1, double x2, double y2)
    {
       double dtheta,theta1,theta2;
    
       theta1 = atan2(y1,x1);
       theta2 = atan2(y2,x2);
       dtheta = theta2 - theta1;
       while (dtheta > PI)
          dtheta -= TWOPI;
       while (dtheta < -PI)
          dtheta += TWOPI;
    
       return(dtheta);
    }
    

    Source: http://paulbourke.net/geometry/insidepoly/

    Other places you can take a look at:
    http://alienryderflex.com/polygon/

    http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html

    http://sidvind.com/wiki/Point-in-polygon:_Jordan_Curve_Theorem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question already has an answer here: What are Extension Methods? 5 answers Usage
This question already has an answer here: How do I enumerate an enum in
This question already has an answer here: Is there ever a reason to not
This question has already an answer here: How do you clear your MRU list
This question to which I already found the answer is posted here in case
I realise the info to answer this question is probably already on here, but
This question has already been posted before, however, the correct answer doesn't seem to
I apologise if this question has already been asked on here before but I
Python beginner here, so I apologize if this question has a simple answer. (I
This question has been asked here before . The accepted answer was probably obvious

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.