Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411582 Posts in 69386 Topics- by 58445 Members - Latest Member: Mansreign

May 05, 2024, 10:11:56 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Detect Circle and line-segment intersection
Pages: [1]
Print
Author Topic: Detect Circle and line-segment intersection  (Read 5951 times)
valkrin
Level 0
***


View Profile
« on: February 20, 2009, 06:27:03 AM »

Hello,
I've Googled for this particular item but anything that I've found I fail to understand. Most of what I found was for Line and Circle intersection. Can someone please explain how this works? Thanks, and I apologize for my ignorance and poor math skills.
Logged
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #1 on: February 20, 2009, 06:57:55 AM »

If it is a line, rather than a line segment, then the circle intersects the line if the distance from the centre of the circle to the closest point on the line is smaller than the circle's radius.

If you imagine moving a circle around near the line, and whenever the circle intersects the line, you draw a red line from the middle of the circle to the line, you'll find the closest point on the line to the circle always makes a right angle to the line towards the circle's centre.



Now if you have a line segment, the way to think about it is in three sections - the line segment; the area beyond one end of the line segment; and the area to the other end of the line segment. If your circle's centre is in the area defined by the line segment swept along a direction perpendicular to the line segment, then you can use the above calculation to find the distance from the centre of the circle to the line. Otherwise, it becomes a simple matter of finding the distance from the centre of the circle to whichever end of the line segment is closer.


Logged

valkrin
Level 0
***


View Profile
« Reply #2 on: February 21, 2009, 11:05:06 AM »

Thanks! That was a very clear explanation, exactly what I needed.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic