Octagonal Area

Joker(Div)

Always Here..
Reaction score
86
How would you check if someone entered an octagonal area? I'm trying to avoid a high-frequency terrain check.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
I found Vexorian made "GroupEnumUnitInPolygon", try to find it. I think u may put 0.5 seconds checkup.
 

Builder Bob

Live free or don't
Reaction score
249
Just create a function that outputs a region with an octagonal shape.

JASS:
function CreateOctagonalRegion takes real centerX, real centerY, real radius returns region

RegionAddCell() will add 32x32 cells to the region. Some math is required here. Will you be alright?

Use this region with TriggerRegisterEnterRegion()
 

Builder Bob

Live free or don't
Reaction score
249
I did some research in an attempt to make a universal function for any regular polygon you could want added to a region. This is what I came up with. It does leave some spots open unfortunately.

As a workaround, you can reduce CELL to 16 to remove all spots. This will make the function half as fast though.

RegionAddPolygon:
JASS:
library RegionFunctions

globals
	private constant real CELL = 32.
	private constant real HALF_CELL = 16.
endglobals

private function RegionAddGon takes region whichRegion, real x1, real y1, real apothem, real angle, real side returns nothing
	local real length = HALF_CELL
	local real width
	local real offset
	local real dx = Cos(angle)
	local real dy = Sin(angle)
	local real x
	local real y
	loop
		set width = side * length / apothem
		set offset = -.5 * width + HALF_CELL
		loop
			set x = x1 + length * dx - offset * dy
			set y = y1 + length * dy + offset * dx
			call RegionAddCell(whichRegion, x, y)
			exitwhen(offset >= .5 * width)
			set offset = offset + CELL
		endloop
		exitwhen(length >= apothem)
		set length = length + CELL
	endloop
endfunction

function RegionAddPolygon takes region whichRegion, real x, real y, real radius, integer polygons, real angle returns nothing
	local real apothem = radius * Cos(bj_PI / polygons)
	local real side = 2. * radius * Sin(bj_PI / polygons)
	local real arc = 2. * bj_PI / polygons
	loop
		exitwhen(polygons <= 0)
		call RegionAddGon(whichRegion, x, y, apothem, angle + arc / 2., side)
		set angle = angle + arc
		set polygons = polygons - 1
	endloop
endfunction

endlibrary


If anyone have any suggestions for improvement, I'd very much like your input.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top