We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Objects inside circle
Page Index Toggle Pages: 1
Objects inside circle? (Read 1327 times)
Objects inside circle?
Jun 5th, 2010, 8:13pm
 
Hi,

I'm trying to create a Boids program I've based off several examples I've found in the forum.
When my boids get to the edge of the window they bounce back and turn around. What I want to do is the same thing, but have it as a circle instead. So when the boids reach the edge of the circle they bounce back. I'm new to processing and was wondering what the easiest, fastest or most efficient way of doing this would be. I would also like to be able to change the shape of the outside boarder if needed, so one time it might be a circle but then I change it to a hexagon.
Any help would be appreciated. Thanks in advance.
Re: Objects inside circle?
Reply #1 - Jun 6th, 2010, 1:32am
 
a circle is pretty easy, instead of checking if it is inside your screenborder. check for a distance to a given point.

if(dist(circle.x,circle.y,boid.x,boid.y)>radius) turn arround;

all other shapes are a bit more complicated. in this case it might be useful to use a library.
http://www.ricardmarxer.com/geomerative/
geomerative is a good library to check if a point is inside a given shape.
Page Index Toggle Pages: 1