HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Choosing Units Within a Triangle

06-04-2006, 08:23 PM#1
MysticGeneral
I want to choose all units within a triangle. I have this trigger atm...

Trigger:
Untitled Trigger 001
Collapse Events
Player - Player 1 (Red) types a chat message containing now2 as An exact match
Conditions
Collapse Actions
Collapse Unit Group - Pick every unit in (Units in (Region((X of ((Position of PlayerHero[0]) offset by 150.00 towards ((Facing of PlayerHero[0]) + 35.00) degrees)), (Y of (Position of PlayerHero[0])), (X of ((Position of PlayerHero[0]) offset by 150.00 towards ((Facing of (Triggering unit)) - 35.00 and do (Actions)
Collapse Loop - Actions
Game - Display to (All players) the text: (Name of (Picked unit))

And it doesn't pick up anything. I don't know if my coordinates are wrong or what? Does anyone know how the points are connected?

Ok, that's a pretty lengthy action. I'll shorten it up.

MinX = Region((X of ((Position of PlayerHero[0]) offset by 150.00 towards ((Facing of PlayerHero[0]) + 35.00) degrees))

MinY = (Y of (Position of PlayerHero[0]))

MaxX = Region((X of ((Position of PlayerHero[0]) offset by 150.00 towards ((Facing of PlayerHero[0]) - 35.00) degrees))

MaxY = (Y of (Position of PlayerHero[0]))
06-04-2006, 09:21 PM#2
TaintedReality
You're making a rectangle.
Quote:
MinY = (Y of (Position of PlayerHero[0]))
MaxY = (Y of (Position of PlayerHero[0]))

Of course it's going to select nothing, the distance between MinY and MaxY is 0, so therefore nothing gets selected ^^.

Use http://www.wc3jass.com/viewtopic.php?t=237.

To use it, first you will need to create a group variable, which here I will name 'TempGroup'. You'll need something like this:
Trigger:
Custom Script: set udg_TempGroup = CreateGroup()
Custom Script: call GroupAddUnitsInTriangle(udg_TempGroup,x1,y1,x2,y2,x3,y3)

Where x1 and y1 are the coordinates of the first point, x2 and y2 are the coordinates of the second, etc.

Then use:
Trigger:
Unit Group - Pick every unit in (TempGroup) and do (Actions)
06-04-2006, 09:24 PM#3
MysticGeneral
Quote:
Of course it's going to select nothing, the distance between MinY and MaxY is 0, so therefore nothing gets selected ^^.

I did that so that the triangle's point is at the hero... If that made any sense, anyways.

Quote:
Where x1 and y1 are the coordinates of the first point, x2 and y2 are the coordinates of the second, etc.

Thing is, I don't which order the dots are connected.
06-04-2006, 09:42 PM#4
TaintedReality
Quote:
I did that so that the triangle's point is at the hero... If that made any sense, anyways.

But you're creating a rectangle. Rectangles with the same minY and maxY are lines.

Quote:
Thing is, I don't which order the dots are connected.

It doesn't matter. I even drew up a lovely image for you =D.
Attached Images
File type: jpghax triangles.jpg (18.4 KB)
06-04-2006, 10:30 PM#5
MysticGeneral
Alright, thanks.
06-05-2006, 03:49 PM#6
blu_da_noob
To clarify: rects in WC3 are always rectangular, the coordinates you specify aren't the coordinates of the corners, but the coordinates along which the vertical and horizontal sides will be placed.
06-05-2006, 07:20 PM#7
The)TideHunter(
Man!! iv been trying for nearly a hour for a function that works like this, takes x1, y1, x2, y2, x3 and y3, then picks all units in those coords, it should make a triangle shape.

This is SO confusing!

Anybody got a algorithm for this? i would love to see it.
This is definatly not impossible, i was thinking of reflecting the triangle from the hypotimuse and creating a square or rect, but then i would have the same problem as i did at the start.

Seen as though the triangle dosent have to be like this:

Zoom (requires log in)

It can be complicated like this:

Zoom (requires log in)

This is a hard 1 to crack unless you know a algorithm for it.

Please help on this thread everybody!

EDIT: sorry for the rediculous image size, it was not intended, i will go and change it

EDIT2: Changed
Attached Images
File type: gifcomplicated.GIF (2.1 KB)
File type: gifsimple.GIF (1.6 KB)
06-05-2006, 07:33 PM#8
blu_da_noob
Collapse JASS:
function IsPointInTriangle takes real x1, real y1, real x2, real y2, real x3, real y3, real x, real y returns boolean
    local real calc1 = (y-y1)*(x2-x1) - (x-x1)*(y2-y1)
    local real calc2 = (y-y3)*(x1-x3) - (x-x3)*(y1-y3)
    local real calc3 = (y-y2)*(x3-x2) - (x-x2)*(y3-y2)
    return (calc1*calc2>0) and (calc3*calc2>0)
endfunction

Function made by Daelin, taken from the JASS Vault.
06-05-2006, 07:36 PM#9
Orc Dork
Is it just me or would an equilateral triangle be better suited to this situation instead of the scaline and right ones that are presented in your posts?
06-05-2006, 09:10 PM#10
TaintedReality
Quote:
Anybody got a algorithm for this? i would love to see it.

Tide, I already posted http://www.wc3jass.com/viewtopic.php?t=237 ><. So yes, someone does have an algorithm for it =P.
06-07-2006, 12:45 AM#11
st33m
Sorry to revie this, but is there a way to get a triangle in GUI?
06-07-2006, 01:19 AM#12
TaintedReality
No, unless you make a method yourself (which would be stupid considering you can get all units within it with just two lines of custom script). And it would probly be tough in GUI. And then you would have to use globals if you wanted it to return values. So basically, you could possibly do it, but it would be a lot of work for no reason.

Edit: What you could do is make a ton of very skinny (actually I guess it would be very short) rectangular preplaced regions, then add them together into a global region variable. Then you could move that around and select all units in it. Don't think you could rotate it though. So again, lots of work when you could just use one nice JASS function and do it all for you =P.
06-07-2006, 01:24 AM#13
st33m
Hmmm... well that sucks, because I have yet to learn JASS (Yes I know it would be easy with all the resources, maybe I'll try over summer...) and dont know if I could impliment this...
06-07-2006, 01:28 AM#14
TaintedReality
If you just want to add units within a triangular region to a unit group, just use these steps.

1. Copy all the code found http://www.wc3jass.com/viewtopic.php?t=237 into your Custom Script section. (At the top of the tree in the Trigger Editor, it says your map name and has a little map icon on the left).

2. Make a global variable named TempGroup, with type Unit Group.

3. Use this custom script:
Trigger:
Custom Script: set udg_TempGroup = CreateGroup()
Custom Script: call GroupAddUnitsInTriangle(udg_TempGroup,x1,y1,x2,y2,x3,y3)

Where x1, y1 is the first point, x2,y2 the second, etc. Now you can pick every unit in TempGroup and do whatever you want to em.

Very easy steps ; ). Only problem might be figuring out what points you want to use.
06-07-2006, 01:31 AM#15
st33m
Oh, that makes sense.

But figuring out points would be easy in my case, because I'd like to just use a set region... so I can just check from the editor.

Thanks.

EDIT: One question. When using that script what it does is make a unit group and then pick every unit in the x1,y1,x2,y2,x3,y3 area right? So how would I decide where that area is?