Forum

> > CS2D > Scripts > Circle area function
Forums overviewCS2D overview Scripts overviewLog in to reply

English Circle area function

11 replies
To the start Previous 1 Next To the start

old Circle area function

Deleted User

Quote
Hi guys
Next function will return true if position x|y is in square area
started from x1|y1 and finished from x2|y2
1
2
3
function area(x, y, x1, y1, x2, y2)
	return x >= x1 and y >= y1 and x <= x2 and y <= y2
end

My problem is:
How to make circle area except of square?

old Re: Circle area function

Apache uwu
User Off Offline

Quote
So you want to test the area within a circle+radius?

Okay...

1
2
3
4
5
function in_circle(playerid,centerX,centerY,radius)
	if math.sqrt(player(playerid,"x"))^2+player(playerid,"y"))^2)<=radius then
		return true
	end
end

or

1
2
3
4
5
function in_circle(targetX,targetY,centerX,centerY,radius)
	if math.sqrt(targetX^2+targetY^2)<=radius then
		return true
	end
end

or even this: I'm finding the angle using the tan ratio, then using the sin ratio to find the hypotenuse.

1
2
3
4
5
function in_circle(targetX,targetY,centerX,centerY,radius)
	if (targetY-centerY)/math.sin(math.atan2(targetX-centerX,targetY-centerY))<=radius then
		return true
	end
end

**Hope I didn't make any errors**

edited 2×, last 23.09.11 08:00:01 pm

old Re: Circle area function

Deleted User

Quote
Textual Context i dont need player position I need only X|Y setted no player needed

BTW u can do
1
return math.sqrt(player(playerid,"x"))^2+player(playerid,"y"))^2)<=radius
except of this:
1
2
3
if math.sqrt(player(playerid,"x"))^2+player(playerid,"y"))^2)<=radius then
          return true
     end
Edit:
And better to use tiles expect of pixels

old Re: Circle area function

Deleted User

Quote
Yeah
BTW not working here what i got:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function var.area(x, y, cx, cy, rad)
	if math.sqrt(x ^ 2 + y ^ 2) <= rad then
		return true
	end
end

function hud.walkarea(id, a)
	for x = 0, map'xsize' do
		for y = 0, map'ysize' do
			if var.area(player(id, 'tilex'), player(id, 'tiley'), x, y, a) then
				local d = image(gfxpath ..'tile_move.png', x * 32 + 16, y * 32 + 16, 0, id)
				table.insert(client.areapos[id], d)
			end
		end
	end
end

addhook('movetile', 'hook.movetile')
	hud.walkarea(id, 5)
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview