HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Pushing/Pulling Units Into/Away from an N-Sided Figure

10-15-2007, 10:08 AM#1
Pyrogasm
So I have a regular, n-sided figure (in the below examples it has 5 sides), and there might be some units inside it, there might be some outside it, some near the edges.

What I'm trying to do is pick all the units on an inner portion of this figure and move them towards the center whilst also pushing all units around the outside away. The following picture illustrates this: units in the yellow area should be pulled to the inner part of the figure and units in the blue should be pushed outwards:
Zoom (requires log in)

The green dots obviously being the vertexes of the figure and the red lines being the "edge" of the figure.

Now, here's my predicament: how do I find out where project X/Y values to find the vertexes of those 10 separate quadrilaterals (5 that will pull in; 5 that push out). The best way to show what I need is to draw a picture:

Zoom (requires log in)

Please note that I need to do this for all n sides of this figure, so just saying "There's a right angle there" isn't going to help me; I just happened to draw it that way.

Also, I just realized I drew my X/Y axis the wrong way. The horizontal should be X, not Y as the picture states, and vice versa for the vertical.

Cheerio.
Attached Images
File type: jpgFigure 2.jpg (61.3 KB)
File type: jpgFigure 1.jpg (64.3 KB)
10-15-2007, 11:31 AM#2
cohadar
The easiest method to calculate Xn Yn points is to notice that all these points are on a circle.

For 5 sided figure angle between center of figure and 2 near points is 360/5 = 72

So you do CosBJ(72*k) and SinBJ(72*k) k=0..n-1

To find out if unit is inside polygon use unit inside triangle function (you can find the fastest implementation on jass vault site)

So for 5 sided polygon you do
InTriangle(center, P0, P1)
InTriangle(center, P1, P2)
InTriangle(center, P2, P3)
InTriangle(center, P3, P4)
InTriangle(center, P4, P0)
10-15-2007, 12:16 PM#3
blu_da_noob
You could do what cohader suggested to group all the units in the polygon (using the triangles). You could then use computational geometry to find the distance between the unit and the outer edge (of the triangle you are checking for). That would allow you to filter for units only just inside the polygon (that would also be possible with two triangle groupings, but computational geometry should be faster).
10-15-2007, 12:26 PM#4
cohadar
For n-sided polygon you need n-2 InTriangle functions.

Picture is worth a thousand words:
Zoom (requires log in)

@blu_da_noob
would you be so kind to learn to spell my nick, it really is not that complex...
Attached Images
File type: pnghmm.PNG (2.6 KB)
10-15-2007, 03:25 PM#5
PipeDream
If I'm understanding your problem correctly-
  • Start with a groupenum with a radius just big enough to hold the entire interesting region.
  • Compute the distance between line segment and point for one of your original edges and a unit. Save the normal vector from line to unit.
  • Pick the minimum distance
  • If it's less than the thickness of the push/pull regions, push the unit by the normal vector. The normal vector will come in a + and - sign which will let you determine which way is in and which is out.
10-16-2007, 03:03 AM#6
MaD[Lion]
there is a polygon detection system out tere, u can use it to detect if a unit is inside or outside a poygon :) and then just push them
10-16-2007, 03:41 AM#7
Pyrogasm
Quote:
Originally Posted by MaD[Lion
]there is a polygon detection system out tere, u can use it to detect if a unit is inside or outside a poygon :) and then just push them
Me != vJASS

And the problem was not detecting units inside the quad, it was getting the vertexes. I've figured it out now and I'm just going to use some concentric circles and figure out what the X/Y values are by projecting onto that circle at the specific angle.
10-16-2007, 10:52 AM#8
cohadar
Where is my rep biach :)
khe khe khe.
10-16-2007, 10:59 AM#9
The Elite
Quote:
Originally Posted by cohadar
Where is my rep biach :)
khe khe khe.
Ill rep you if you rep me
10-16-2007, 11:17 AM#10
cohadar
Sorry but I am strait.
10-16-2007, 07:11 PM#11
Pyrogasm
You even spelled "straight" wrong.