Sign in to follow this  
FounderSim

How to figure out if something is in the area of a circle?

Recommended Posts

FounderSim    248

I tried google for some circle equations to figure out the equation for this but what I pulled up what not relevant. What I want to do is give a weapon some sort of result if the target is within the range of a circle. I figured the best way to do this would be to get where the "weapon" lands (x,y) and compare it to the outside perimeter of the circle's co-responding (x,y), but i couldnt find such a thing to grab certain (x,y) spots of the outside perimeter based on a x,y position.

Share this post


Link to post
Share on other sites
cadjunkie    1890

Find the implicit equation for the circle centered at (a,b): (x-a)^2+(y-b)^2-R^2=0 and plug the point into the left hand side of the equation. If the point is within the circle, then the answer will be negative. If the point is on the circle, it will be zero. If the result is positive, then the point is outside the circle.

 

EDIT: can't get the LaTeX working.

Edited by cadjunkie

Share this post


Link to post
Share on other sites
Brain    18906

If you want to determine whether a point (tx,ty) is within a circle with its centre at (x,y) then you need to determine whether (x-tx)2 + (y-ty)2 is less than r squared (where r is the radius of the circle or what you are referring to as the range)

 

While this is correct, it can be explained in a more familiar way. it is simply pythagoras theorem as taught in high school,  Google it up if you don't remember it, it's quite easy even for a maths hater like me...

Edited by braindigitalis

Share this post


Link to post
Share on other sites
DiegoSLTS    2113

I'm not sure if the OP wants to detect if a point is inside a circle. He wrote about a "target" and in games a target is usually some kind of object that has a size, so checking a point might give wrong results. To the OP, if you want to do that thing I said you should research about collision detection, so you can detect a valid target even if only a part of the target is at a certain distance of the weapon.

Share this post


Link to post
Share on other sites
cadjunkie    1890

I'm not sure if the OP wants to detect if a point is inside a circle. He wrote about a "target" and in games a target is usually some kind of object that has a size, so checking a point might give wrong results. To the OP, if you want to do that thing I said you should research about collision detection, so you can detect a valid target even if only a part of the target is at a certain distance of the weapon.

 

Can't the OP just get some sort of bounding box/convex hull and tests each point if it lies inside the circle? I guess this is a weaker form of collision detection, but it might be tenable given the point-in-circle test is really computationally simple.

Share this post


Link to post
Share on other sites
DiegoSLTS    2113

 

I'm not sure if the OP wants to detect if a point is inside a circle. He wrote about a "target" and in games a target is usually some kind of object that has a size, so checking a point might give wrong results. To the OP, if you want to do that thing I said you should research about collision detection, so you can detect a valid target even if only a part of the target is at a certain distance of the weapon.

 

Can't the OP just get some sort of bounding box/convex hull and tests each point if it lies inside the circle? I guess this is a weaker form of collision detection, but it might be tenable given the point-in-circle test is really computationally simple.

 

Yes, in most cases it might work, but you can have two points outside of the area and the line between them could intersect with it anyway. It depends on how accurate the detection should be, and that depends on the gameplay.

 

In some games modeling the colision areas as circles is good enough and in those cases the colision detection requires the same work as checking for a point inside a circle, but instead of checking if the point is at a distance less than the range, you check if the distance between them is less than the range plus the radius of the target area.

Share this post


Link to post
Share on other sites
cadjunkie    1890

 

 

I'm not sure if the OP wants to detect if a point is inside a circle. He wrote about a "target" and in games a target is usually some kind of object that has a size, so checking a point might give wrong results. To the OP, if you want to do that thing I said you should research about collision detection, so you can detect a valid target even if only a part of the target is at a certain distance of the weapon.

 

Can't the OP just get some sort of bounding box/convex hull and tests each point if it lies inside the circle? I guess this is a weaker form of collision detection, but it might be tenable given the point-in-circle test is really computationally simple.

 

Yes, in most cases it might work, but you can have two points outside of the area and the line between them could intersect with it anyway. It depends on how accurate the detection should be, and that depends on the gameplay.

 

In some games modeling the colision areas as circles is good enough and in those cases the colision detection requires the same work as checking for a point inside a circle, but instead of checking if the point is at a distance less than the range, you check if the distance between them is less than the range plus the radius of the target area.

 

 

You're right. The amount of collision detection does depend on the gameplay, but even in the case that the OP wants to do some sort of line-circle intersection test, the test is really simple as well. I wrote an article explaining how to do the simple test if the line intersects, is tangent to, or doesn't intersect the circle. It would also be trivial to figure out at which points the line intersected the circle.

 

http://www.gamedev.net/page/resources/_/technical/math-and-physics/advanced-intersection-test-methods-r3536

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this