Finding Intersections Between Circles and Lines: A Programmer's Guide

  • Thread starter Pazil
  • Start date
In summary, the conversation is about a grade 10 Flash programmer who is building a collision detection library and needs help with finding the intersection points between a circle and a line. The solution involves translating the coordinates, reducing the case to center at origin, and using the equation x^2 + y^2 = r^2. The conversation also discusses how to solve for the quadratic formula and how to factor the equation. Additional topics discussed include testing the solution and parametrizing the equations for lines and circles.
  • #1
Pazil
8
0
Hi!

I'm new to these forums, and a grade 10 Flash programmer. I'm currently building a collision detection library, with which I currently have Lines and Circles.

My problem is that I don't know how to get the intersection points between a circle and a line. I'm using mx+b for the line, in other words infinite lines. I already have intersection with the equation x^2 + y^2 = r^2 good to go, but I have no idea how to translate this into:
(x - h)^2 + (y - k)^2 = r^2, in other words add coordinates to the intersection calculation. I only need the calculations up to the point where I can get A, B, and C variables for the quadratic formula (from then on it's simple plugging in).

Any help what so ever is greatly appreciated! I just found these forums, and it seems as though I'll be in heaven from now on!

P.
 
Physics news on Phys.org
  • #2
If you define new coordinates (by translation):

x1 = x-h
y1 = y-k

then you have reduced to the case you already know (center at origin):

x1^2 + y1^2 = r^2

y1+k=m(x1+h)+b, i.e y1=mx1+(b+mh-k)

Compute the intersection and convert the result back to (x,y)-coordinates.
 
  • #3
Alright, I'll try that!

Thank you!

Edit:

I'm still a bit confused, since I have no idea how to get that into Ax^2 + Bx + C = 0 form...?
I get to (1 + m^2)x1^2 + (b + mh - k)^2 = r^2
But I don't see how to get a B for Bx, since there's no x1 terms.
 
Last edited:
  • #4
Then B= 0. In fact, that form is particularly easy to solve. If [itex]ax^2+ bx+ c= 0[/itex] and b= 0, [itex]ax^2+ c= 0[/itex] or [itex]ax^2= -c[/itex] so [itex]x^2= -c/a[/itex] which has real roots if and only if -c/a is non-negative and in that case [itex]x= \pm\sqrt{-c/a}[/itex].
 
Last edited by a moderator:
  • #5
Alright then. I guessed that much, and I realized that B would then be excluded, but I just don't understand how this form, which includes the x/y coordinates factors to only:
Ax^2 + c = 0
When if you do:

x^2 + y^2 = r^2
y = mx + b

x^2 + (mx+b)^2 = r^2

(1+m^2)x^2 + 2mbx + b^2 - r^2 = 0
Therefore:
A = 1+m^2
B = 2mb
C = b^2 - r^2

I realize that it has to do with assigning x1 = x - h and same for the y, but I just don't understand how you would factor it still...I mean, I do, but...I hate when I do something in Math, and I don't understand what's happening.
Please go easy on me, since I'm in grade 10 (I mean, not easy...but just, explain a bit more please?)

P.
 
  • #6
Pazil said:
(1+m^2)x^2 + 2mbx + b^2 - r^2 = 0
Therefore:
A = 1+m^2
B = 2mb
C = b^2 - r^2

That is correct.

I get to (1 + m^2)x1^2 + (b + mh - k)^2 = r^2

Here you forgot the 2mx1(b+mh-k) term.
 
  • #7
Well, I apologize for the seemingly empty posts I've been writing, but I haven't had enough time to totally just sit down and work out the things you threw at me.
I tried to collect all like terms again, and this is what I got (Ax^2 + Bx + C = 0):

(1 + m^2)x^2 + (-2h + 2bm - 2km)x + h^2 + b^2 - 2kb + k^2 - r^2 = 0
This is from (x - h)^2 + (mx+b - k)^2 = r^2

Does it look alright to you guys?

P.
 
  • #8
Pazil said:
Well, I apologize for the seemingly empty posts I've been writing, but I haven't had enough time to totally just sit down and work out the things you threw at me.
I tried to collect all like terms again, and this is what I got (Ax^2 + Bx + C = 0):

(1 + m^2)x^2 + (-2h + 2bm - 2km)x + h^2 + b^2 - 2kb + k^2 - r^2 = 0
This is from (x - h)^2 + (mx+b - k)^2 = r^2

Does it look alright to you guys?

P.

Looks good :) It's also good to test the solution by plugging in a few values for m,b,etc and see if the solutions satisfy the equations of the line and the circle.

How do the results change if the line is expressed as ax+by+c=0 (this includes the vertical line when b=0).
 
  • #9
I just tested in my collision engine and it works perfectly also!

How would I plugin in the ax + by + c = 0 into the (x - h)^2 + (y - k)^2 = r^2 equation?
Supporting vertical lines would of course be a big bonus!

P.

Or, how could I parametrize this, so that x becomes a function of t?
 
Last edited:
  • #10
Pazil said:
How would I plugin in the ax + by + c = 0 into the (x - h)^2 + (y - k)^2 = r^2 equation?
Supporting vertical lines would of course be a big bonus!

I think that at some point you will have to distinguish between two cases. If b is nonzero in ax+by+c you can solve for y in terms of x. In the other case you could just temporarily switch the x and y coordinates.
 
  • #11
I thought of that just after I posted!

I'm going to try to parametrize my line equations by myself, but I'll definitely need help for parametric circles vs. lines and circles vs. circles...

P.

By the way, in some equations, I spot this: x = 2[ y + jh - 5] or something...what does the 2[] mean? I'm guessing it's just like normal brackets?
 

1. What is a circle-line intersection?

A circle-line intersection refers to the point or points where a circle and a line intersect on a two-dimensional plane.

2. How do you find the intersection points of a circle and a line?

To find the intersection points, you can use algebraic equations or geometric constructions. For algebraic equations, you can set the equations for the circle and line equal to each other and solve for the variables. For geometric constructions, you can draw the circle and line on a graph and use the properties of circles and lines to locate the intersection points.

3. Can a circle and a line intersect at multiple points?

Yes, a circle and a line can intersect at one, two, or even infinitely many points. This depends on the position of the circle and line in relation to each other and the properties of their equations.

4. What is the significance of circle-line intersections in geometry?

Circle-line intersections play a crucial role in understanding and solving geometric problems involving circles and lines. They also have many real-world applications, such as in engineering, architecture, and navigation.

5. Are there any special cases for circle-line intersections?

Yes, there are a few special cases for circle-line intersections. One example is when the circle and line are tangent to each other, meaning they touch at exactly one point. Another case is when the circle and line are parallel and do not intersect at all.

Similar threads

  • Calculus
Replies
14
Views
1K
Replies
4
Views
2K
  • Calculus
Replies
10
Views
2K
Replies
2
Views
262
Replies
4
Views
785
  • Calculus
Replies
29
Views
677
Replies
20
Views
2K
Replies
2
Views
253
  • Precalculus Mathematics Homework Help
Replies
5
Views
917
Replies
4
Views
821
Back
Top