Page 1 of 1

GetCoordsincircle

Posted: Sat Sep 01, 2007 11:16 am
by Unfaithful
I dont have any idea how make GetCoordinCircle maybe someone have?

this is square example from 097

Code: Select all

function GetCoordsInSquare(mid_x, mid_y, radius)
	var x_row := CInt(mid_x)-CInt(radius);
	var y_col := CInt(mid_y)-CInt(radius);
	var stop_x := CInt(mid_x)+CInt(radius);
	var stop_y := CInt(mid_y)+CInt(radius);

	var point_list := array{};
	var coord := struct{"x", "y"};
	
	for ( x_row:=(mid_x-radius); x_row<=stop_x; x_row:=x_row+1 )
		for ( y_col:=(mid_y-radius); y_col<=stop_y; y_col:=y_col+1 )
			coord.x := x_row;
			coord.y := y_col;
			point_list.Append(coord);
			SleepMS(2);
		endfor
		SleepMS(2);
	endfor
	
	return point_list;
endfunction

Posted: Sat Sep 01, 2007 7:11 pm
by CWO
are you talking of an actual circular pattern? or more of a diamond type pattern?

Posted: Sun Sep 02, 2007 3:38 am
by Unfaithful
doesnt matter it can be circle or diamond i need i to make for exapmle champion, when champion dies above his corpse in "circle" scripts creates a lot of gold stacks - see it in runuo its not exactly circle but almost

Posted: Sun Sep 02, 2007 7:47 am
by Austin
It involves a lot of trig and we never could find a math expert to figure out how to make it. We also noted that the smaller the radius, the less accurate it becomes.

Posted: Mon Sep 03, 2007 1:42 pm
by RazorTongue
You can do it in a brute force way. Knowing the radius(r) and the magic formula (x-x1)^2 + (y-y1)^2 <= r^2 and the center point(x1, y1), run two loops like that:

R2 = r^2
for(X = x1-r to x1+r)
for(Y = y1-r to y1+r)
if (pow(X-x1, 2) + pow(Y-y1, 2) <= R2)
; // in circle

Running time: O(r^2)

Alternative way - generate config files with patterns from 1 to XX(your max) and load on demand.

Running time: O(1)

Posted: Tue Sep 04, 2007 8:03 am
by Unfaithful
thx, i think i will handle it