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 660193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:07:45+00:00 2026-05-13T23:07:45+00:00

In my XNA game, I needed to define an irregular shape based on several

  • 0

In my XNA game, I needed to define an irregular shape based on several Vector2 coordinates in the 2D space. The reason was to do collision check (like Rectangle.Intersects()).

For example:

Vector2 point1 = new Vector(20,30);
Vector2 point2 = new Vector(60,30);
Vector2 point3 = new Vector(60,80);
Vector2 point4 = new Vector(40,90);
Vector2 point5 = new Vector(20,80);

would create a shape that has paths that goes from point1 -> point2 -> point3 -> point4 -> point5 then back to point1.

However I couldn’t find a proper solution to implement this. Please help. Thanks.

  • 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-05-13T23:07:45+00:00Added an answer on May 13, 2026 at 11:07 pm

    There are a couple of different approaches to what you want to do. You mentioned collision detection: do you want to determine if a point intersects the shape, or do you want to determine if two polygons intersect?

    If you want a point, what you’re looking for is called a “point in polygon test”. There are a number of different approaches, but one of the quickest and most straight forward approaches is a ray test. You create a ray from your point and count the number of times it crosses the edges. If the number is even, the point is outside. If it’s odd, the point is inside.

    You can find a good article on this here: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html

    The code implementation from the article looks like so:

    int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
    {
      int i, j, c = 0;
      for (i = 0, j = nvert-1; i < nvert; j = i++) {
        if ( ((verty[i]>testy) != (verty[j]>testy)) &&
         (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
           c = !c;
      }
      return c;
    }
    

    Determining if two polygons intersect is more complicated, but not entirely dissimilar. A lot of games actually just check the corners of the polygons with point-in-poly as its easy and cheap, but it is possible to check the complete intersection as well.

    One way you can approach it is to treat each edge as a dividing plane / halfspace. The intersection of the halfspaces determines if the two polygons intersect.

    Try searching for “Separating Axis Theorem”.

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

Sidebar

Related Questions

For some reason the XNA Game Studio doesn't work on my PC. :( .
I would like to implement a ballistic trajectory in an XNA game and was
I'm making a highscorelist for my XNA game. I would like to make it
I'm writing an XNA game where I do per-pixel collision checks. The loop which
I've developed an XNA game that I'd like to show a few people at
I have develop an XNA game on computer 1. When I send it to
I'm developping an XNA game and I usually start my application in windowed mode
I'm writing an XNA game in C# using the XNA port of Box2d -
I'm creating an XNA game and am getting an unexpected result, extremely low FPS
I have XNA game and it contains these classes public partial class Bird :

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.