- Joined
- Nov 22, 2006
- Messages
- 1,260
You do know that the unit will have to be facing either 90 degrees or 270 degrees, right?
This is because you can't create a rect that goes diagonal or in any shape other than a straight square/rectangle. I'm not sure if this would work too well because of this.
If this isn't what you need
http://www.wc3campaigns.net/attachme...chmentid=28614
then you don't know what you need.
function CorrecTAngle takes real Angle returns real
local real NewAngle = Angle
if NewAngle > 360 then
loop
exitwhen NewAngle < 360
set NewAngle = NewAngle - 360
endloop
endif
if NewAngle < 0 then
loop
exitwhen NewAngle > 0
set NewAngle = NewAngle + 360
endloop
endif
return NewAngle
endfunction
function CorrecTAngle takes real Angle returns real
local real NewAngle = Angle
if NewAngle > 360 then
loop
exitwhen NewAngle < 360
set NewAngle = NewAngle - 360
endloop
endif
if NewAngle < 0 then
loop
exitwhen NewAngle > 0
set NewAngle = NewAngle + 360
endloop
endif
return NewAngle
endfunction
function DoSomething takes nothing returns nothing
local real Width //width of rectangle
local real Leng //length of rectangle
local real StartPointX //Starting point
local real StartPointY //Second starting point
local real StartAngle //Angle of rectangle
local real Point1X = StartPointX + (1/2 * Width) * Cos(CorrecTAngle(StartAngle + 90) * bj_DEGTORAD)
local real Point1Y = StartPointY + (1/2 * Width) * Sin(CorrecTAngle(StartAngle + 90) * bj_DEGTORAD)
local real Point2X = StartPointX + (1/2 * Width) * Cos(CorrecTAngle(StartAngle - 90) * bj_DEGTORAD)
local real Point2Y = StartPointY + (1/2 * Width) * Sin(CorrecTAngle(StartAngle - 90) * bj_DEGTORAD)
local real Point3X = Point1X + Leng * Cos(StartAngle * bj_DEGTORAD)
local real Point3Y = Point1Y + Leng * Sin(StartAngle * bj_DEGTORAD)
local real Point4X = Point2X + Leng * Cos(StartAngle * bj_DEGTORAD)
local real Point4Y = Point2Y + Leng * Sin(StartAngle * bj_DEGTORAD)
//Point 1 2 3 4 make up the rectangle but NOT in that order. Order going counterclockwise: 1, 2, 4, 3
endfunction
function half takes real k returns real
return k/2
endfunction
function DoSomething takes nothing returns nothing
local real Width //width of rectangle
local real Leng //length of rectangle
local real StartPointX //Starting point
local real StartPointY //Second starting point
local real StartAngle //Angle of rectangle
local real Point1X = StartPointX + half(Width) * Cos(CorrecTAngle(StartAngle + 90) * bj_DEGTORAD)
local real Point1Y = StartPointY + half(Width) * Sin(CorrecTAngle(StartAngle + 90) * bj_DEGTORAD)
local real Point2X = StartPointX + half(Width) * Cos(CorrecTAngle(StartAngle - 90) * bj_DEGTORAD)
local real Point2Y = StartPointY + half(Width) * Sin(CorrecTAngle(StartAngle - 90) * bj_DEGTORAD)
local real Point3X = Point1X + Leng * Cos(StartAngle * bj_DEGTORAD)
local real Point3Y = Point1Y + Leng * Sin(StartAngle * bj_DEGTORAD)
local real Point4X = Point2X + Leng * Cos(StartAngle * bj_DEGTORAD)
local real Point4Y = Point2Y + Leng * Sin(StartAngle * bj_DEGTORAD)
//Point 1 2 3 4 make up the rectangle but NOT in that order. Order: 1, 2, 4, 3
endfunction
vJass REQUIRED!! (If you don't have vJass just play it)
If you want to program something that does a bit of algebra, it would be really easy; project a line of y=(the point's y) from (the point's x) and onwards, and see how many lines it intersects with of the bounds of this generic polygon. If it's odd, it's inside the shape. If it's even, it's outside the shape. (Then you would just enum a circle to get the units to test)