Intersection points of a line on a circle

AI Thread Summary
The discussion revolves around finding the intersection points of a line with a circle for a shooting game. The user has established the equations for the line and the circle but struggles to convert them into a standard quadratic form. Participants suggest using the general form of the circle equation to account for circles not centered at the origin and emphasize the importance of maintaining a consistent coordinate system. They guide the user through the process of rearranging the equations to achieve the standard quadratic form, ultimately leading to the application of the quadratic formula to find intersection points. The conversation concludes with the user expressing confidence in applying the suggested methods.
TOdorus
Messages
5
Reaction score
0
Hi all,

I have a bit of an algebraic problem, and my lack of attention during math is starting to show. I was experimenting with hit detection based on lines for a simple shooting game, and the enemies bieng circulair.

I already have a function to check the distance from the line to the circles centre, so I already know that there is a intersection (or hit). I also would like to know where it intersects, for graphics and some extra physics.

So here's what I got:

Known
r
m
b

so these can be considered constant

Equitions so far

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

this gives:
r^2 = (mx+b)^2 + x^2

And then my troubles begin, because writing that out would give:
r^2 + b^2 = x^2 + mx^2 + 2mbx

Googling around tells me that this is the way to go, and you should get a quadratic function, but I don't know how to solve this kind of equation. Can anybody help out? I hope to finish a prototype soon.

Tnx in advance,

TO
 
Physics news on Phys.org
The equation

x^2 + y^2 = r^2

implies that the center of the circle is at the origin of your coordinate system. You propably should be using the the more general form:

(x-k)^2 + (y-h)^2 = r^2

where the center of the circle is at (k,h)
 
Yes, but that would complecate the problem even more. I was thinking of transforming the line function instead to simplify it, but if anyone knows the solution, that would be better. It would make a more efficient function.
 
Google quadratic formula.

If your circles aren't at the origin, and they're probably not, you'll have to use the more general form \int suggested.

The other option you can do is make (k,h) the 'origin' and have the equation of the line adjusted appropriately.
 
You need to but your quadratic in the standard form

ax^2 + bx +c =0

Then apply the quadradic formula. It is essential that you use a consistent coordinate system. That means that the expression for the line and the circle should plot correctly if you were to draw them out.
 
Integral said:
You need to but your quadratic in the standard form

ax^2 + bx +c =0

Exactly. But how do I go about, getting it to this form?

r^2 = x^2 + y^2
r^2 = x^2 + (mx+b)^2
r^2 = x^2 + mx^2 + 2*bmx + b^2

I have no idea how I can get that to ax^2 + bx +c =0
 
r^2=x^2+mx^2+2bmx+b^2=(1+m)x^2+(2bm)x+b^2

Letting a=(1+m), b=2bmx and c=b^2 you will have it in 'standard form'.

The important thing to realize that there are two different b's and not getting confused.
 
ZioX said:
r^2=x^2+mx^2+2bmx+b^2=(1+m)x^2+(2bm)x+b^2

Letting a=(1+m), b=2bmx and c=b^2 you will have it in 'standard form'.

Ah, thanks a bundle! I overlooked the possibility of x^2 + mx^2 = (1+m)x^2

ZioX said:
The important thing to realize that there are two different b's and not getting confused.

No need to worry about me getting confused over that: I did a ton of these when I was 16. The problem is, that was 7 years ago :-p

I'm going to give (x-k)^2 + (y-h)^2 = r^2 a try after lunch.
 
r^2 = (x-k)^2 + (y-h)^2
r^2 = x^2 -2kx + k^2 + y^2 -2hy + h^2
r^2 = x^2 -2kx + k^2 + (mx+b)^2 -2h(mx+b) + h^2
r^2 = x^2 -2kx + k^2 + m^2x^2 + 2bmx + b^2 - 2hmx - 2hb + h^2

0 = (1-2k+m^2)x^2 + (2bm-2hm)x + (k+b^2-2hb+h^2-r^2)

D = b^2 - 4ac
D = (2bm - 2hm)^2 - 4(1-2k+m^2)(k+b^2-2hb+h^2-r^2)

No real need to evaluate D though, as there are always two intersections in my case.

x = \frac{-b+\sqrt{D}}{2a} or
x = \frac{-b-\sqrt{D} }{2a}
x = \frac{-(2bm-2hm)+\sqrt{D}}{2(1-2k+m^2)} or x = \frac{-(2bm-2hm)+\sqrt{D}}{2(1-2k+m^2)}

Is this right?
 
Last edited:

Similar threads

Replies
5
Views
1K
Replies
26
Views
647
Replies
23
Views
2K
Replies
18
Views
2K
Replies
5
Views
4K
Replies
3
Views
2K
Replies
3
Views
2K
Replies
9
Views
3K
Replies
14
Views
2K
Back
Top