Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Help with some circle line math

Author
Message
blink0k
AGK Developer
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 13th Aug 2018 10:48 Edited at: 13th Aug 2018 10:49
I have two circles that have collided. I need to find the point at which they have collided.
I have the center of each circle and the radius of each circle. How do i calculate where the blue dot is?




Thanks in advance for your help

Attachments

Login to view attachments
Bengismo
2
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 13th Aug 2018 11:58
This works to detect the point of collision xh#,yh#



or if you prefer some trigonometry

Phaelax
DBPro Master
16
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Aug 2018 12:59
He's pretty much already given the solution, but I'll give a brief explanation.

When the two collide (not overlap, as that gives 2 intersection points), the point of intersection is going to be the radius length from center of one of the circles. You just have to determine at which angle, which is simple enough to do. Subtracting the two positions will give you a direction vector.

So X2-X1 will give the direction of circle 1 towards the second. If you prefer an angle of direction instead of a vector, ATAN can be used. Plugging that angle into sin/cos will give a normalized direction vector, at which point you can multiple by the radius of the circle plus the originating center coordinate.

In his first example, he's basically using linear interpolation but because the direction (the first part in parenthesis) isn't normalized, multiplying by the radius gives a much larger value. That is why it's then divided by the overall length of the two radii combined.

If curious, I have several algorithms for testing intersections with shapes.
https://www.zimnox.com/resources/articles/math/?ar=m002
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
blink0k
AGK Developer
7
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 13th Aug 2018 22:21
Wow! Thanks guys. Great response. Thank you both
Golelorn
3
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 14th Aug 2018 01:11
Wow. Cool. This should be stickied lol

Login to post a reply

Server time is: 2020-02-26 07:51:59
Your offset time is: 2020-02-26 07:51:59