|
-
Jul 31st, 2001, 11:18 AM
#1
Thread Starter
Hyperactive Member
collision detection for a circle???
I am new to collision detection with circles. I pretty much know how to do collision detection with rectangles, and i am going to start with circles. to get collision detection for 2 circles, i "think" i would find out the center point of the two circles and then find out the distance between the 2 center points of the 2 circles. Then i would subtract the sum of each circle's radius. If the remaining number is >= 0 then a collision has taken place. If not, a collision hasnt taken place.
So here's my questions:
1. how do i find out the center point of a circle?
2. how do i find out the distance between two center points of 2 circles?
3. how do i find the radius of a circle?
Thanks for any help!
Visual Basic 6, HTML, JavaScript, learning C++
-
Jul 31st, 2001, 11:23 AM
#2
Member
The centerpoints and radii of your circles will need to be known ahead of time. And, in a game, they should be since they'd either be part of the level, or sprites that are moved.
So, then, knowing those, you can get the distance between by using our favorite equation from Pythagoras:
d = sqr( (X2-X1) ^2 + (Y2-Y1) ^2 )
So, if your circles have radii R1 and R2 respectively, then if your calculated d <= R1 + R2, you have a collision ...
Here's a couple of tutorials:
rookscape.com/vbgaming/tutAP.php
rookscape.com/vbgaming/tutBU.php
-Bryk
Edit: Bryk -- added tutorial references
-
Jul 31st, 2001, 01:25 PM
#3
transcendental analytic
In case your circles are not defined by center and radii, we'd need know what you're intending to do, that is what is the problem.
Squareroot is computionally a lot slower than multiplication so to speed it up the detection expression should be:
dx=ax-bx
dy=ay-by
r=ar+br
collision=r*r>dx*dx+dy*dy
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 1st, 2001, 06:50 AM
#4
Thread Starter
Hyperactive Member
i still don't understand how to find the distance between the two center points of 2 circles?
Visual Basic 6, HTML, JavaScript, learning C++
-
Aug 1st, 2001, 07:01 AM
#5
Member
dflw ... In my original reply, I gave the function:
d = sqr( (X2-X1) ^2 + (Y2-Y1) ^2 )
In it, one circle has a centerpoint at (X1, Y1) and the other at (X2, Y2) ... so if you run that line, then d will give you the distance between the circles' centerpoints.
And Kedaman's right that multiplication is much faster in VB than any power-related operators (sqr and "^"), or just about any other math operator.
So, his code showed that if you are just using the calc to determine collision, you don't need to do the sqr function on it -- you can just square the sum of the radii ...
Does that help?
-Bryk
-
Aug 1st, 2001, 07:49 AM
#6
Thread Starter
Hyperactive Member
ok , i get that, but how do i constantly change the x, y coords for the second circle because it moves?
Visual Basic 6, HTML, JavaScript, learning C++
-
Aug 1st, 2001, 08:29 AM
#7
Member
Can you give a little more detailed description of what you're program is doing?
I've been assuming that your circles are things that your program is in control of ... for example, a space ship or player character that the user will be moving around with the mouse, keyboard, or joystick ...
"More info please ..."
-Bryk
-
Aug 1st, 2001, 02:05 PM
#8
Thread Starter
Hyperactive Member
I am not really making a game yet, i 'm just figuring out how to do the basics of games like collision detection. Ok, heres my setup. I have two circles on a form, one of them is static and the other one is moved with the arrow keys. I am assuming that the x,y coords of the center points of the moving circle are constantly changing... so to put the center point x,y coords into the equation, how would i do this?Yeah i sound like a moron but i'm just starting off in games. is this enough info?
thanks for any help.
Visual Basic 6, HTML, JavaScript, learning C++
-
Aug 1st, 2001, 02:13 PM
#9
transcendental analytic
Those should be declared as variables, and the circles should be drawn using the variables. In case you use shape objects, the circle center is centered on the shape, so positioning them would be at center-radius
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Sep 7th, 2009, 10:10 PM
#10
Addicted Member
Re: collision detection for a circle???
this is really old thread, found it from google, lol, but couldn't help replying,
radius is circle.width / 2
the center of a circle is (circle.left + radius, circle.top + radius)
lol 2001, i wont get a reply back, but in case anyone else finds this thread
-
Sep 8th, 2009, 08:58 AM
#11
Re: collision detection for a circle???
 Originally Posted by dflw
I am not really making a game yet, i 'm just figuring out how to do the basics of games like collision detection.
Ok, this is your problem in a nutshell actually. You don't understand exactly what a game is (at least an arcade game) 
A game is a program that when you start it, it runs in a loop. It zips through that loop at least 30 times a second. Every time it does, it draws the graphics on the screen. Why 30? Because that's about the minimum frames per second that the human eye is unable to perceive flickering (most game designers aim for 60 or better)
If you're used to application programming, this type of graphics control was never an issue. Things didn't "move", they just "sat". Windows only updated the graphics when something happened and handled it behind the scenes.
In a Game, the positional information of each object on the screen are CONSTANTLY being updated. Even if a circle on the screen hasn't moved for 10 seconds, the game has updated itself at least 300 times! And every time, it's checking for collision between that circle and another.
-
Sep 9th, 2009, 05:44 AM
#12
Re: collision detection for a circle???
You are aware that dflw has a "Last Activity: Mar 31st, 2002 05:52 PM".
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Sep 9th, 2009, 07:42 AM
#13
Re: collision detection for a circle???
Arrgg... I hate it when someone necro's a thread.
-
Sep 9th, 2009, 08:19 PM
#14
Addicted Member
Re: collision detection for a circle???
 Originally Posted by Jenner
Arrgg... I hate it when someone necro's a thread. 
sorry? lol
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|