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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 320k
  • Answers 320k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm unfamiliar with how to properly subscribe to the Word… May 14, 2026 at 12:23 am
  • Editorial Team
    Editorial Team added an answer An array in C++ is an array of objects laid… May 14, 2026 at 12:23 am
  • Editorial Team
    Editorial Team added an answer For anyone interested in the resolution of this issue: I… May 14, 2026 at 12:23 am

Related Questions

Hokay so here is what I'm trying to accomplish: I'm going to be sending
In a level editor I've made for my XNA game (editor is also in
I'm working on a Map Editor for an XNA game I'm designing in my
I've implemented MultiSampling on my XNA game, it works great on my Desktop. When
I'm using C# WinForms to create a level builder for my XNA game. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.