Creating a Form Using the Vector2 Series - XNA

In my XNA game, I needed to identify an irregular shape based on several Vector2 coordinates in a 2D space. The reason was to run a collision check (e.g. Rectangle.Intersects()).

For instance:

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);

will create a form that has paths from point1point2point3point4point5, then go back to point1.

However, I could not find the right solution for its implementation. Please help. Thank.

+3
source share
2 answers

, . : , , ?

, , , " ​​". , . , . , . , .

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

:

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;
}

, , , . , , .

, , - /. , .

" ".

+2

ZiggyWare ( www.ziggyware.com) , , ZW . , .

0

Source: https://habr.com/ru/post/1735388/


All Articles