drwaing circular boundary

hi ,
i’m trying to draw an empty circle that act like a circular boundary for objects (balls), i used an img for a circle and then used collision to forbid the balls from passing that circle boundary … the problem is :
the balls collide with the whole circle img even the transparent part and go out the whole area , so i used draw points using the circle formala and got forced to draw the empty circular boundary point by point . Is this the only solution to draw circular boundary ?
this is the code i used
[lua][code]

nq = 160 --diameter of the circle
x = 0 – the start point of the circle
xd = 0

–the upper half of the circle
for i = 0 ,320 do
k = x^2-320*x+57600
y = (nq*3 - ((nq*3)^2 -4*k)^(1/2) )/2
cir = display.newCircle (x,y,4)
x = x+1
end

–the lower half of the circle
for i = 0 ,320 do
k = xd^2-320*xd+57600
y = (nq*3 + ((nq*3)^2 -4*k)^(1/2) )/2
cir = display.newCircle (xd,y,4)
xd = xd+1
physics.addBody (cir,“static”, {bounce=0., density=1.0,} )
end
[/code][/lua]

[import]uid: 96650 topic_id: 21969 reply_id: 321969[/import]

Yes, you have to define the share right now - no way of doing a circle boundary without it. [import]uid: 52491 topic_id: 21969 reply_id: 87444[/import]

thx peach :slight_smile:
[import]uid: 96650 topic_id: 21969 reply_id: 87582[/import]

when i do this i ad each single point (circle) to physics engine and this make the application so heavy and slow as u can see i used 650 point to draw a sigle circuit !! plz can any one help me solving this issu [import]uid: 96650 topic_id: 21969 reply_id: 87866[/import]

Maybe you can check their position using maths, instead of using physics?

I can’t work out if you want to keep things inside the circle, or outside the circle.
But the principles should be applicable.

A circle describes the points which are a certain distance from a point.
Say the radius is 50
Any point which is more than 50 pixels away from another point is outside the circle.
All you need to do is work out the absolute distance from x,y to x1,y1 and if it is greater than radius then you act upon it.

Whats the distance?

Pythagoras: the square root of the sum of the other two squares

ie:
math.sqrt
(
((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2) )
)
[import]uid: 108660 topic_id: 21969 reply_id: 87874[/import]

i see , thx :slight_smile:
[import]uid: 96650 topic_id: 21969 reply_id: 87928[/import]