Intersection points of a line on a circle

In summary, the user has a problem with hit detection and is looking for help. They know the distance from the line to the circle's center, and want to know where the hit is. They are trying to solve for the equation in standard form, but are stuck. They believe that they have solved it, but they are not sure.
  • #1
TOdorus
5
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
  • #2
The equation

[tex] x^2 + y^2 = r^2 [/tex]

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:

[tex] (x-k)^2 + (y-h)^2 = r^2 [/tex]

where the center of the circle is at (k,h)
 
  • #3
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.
 
  • #4
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 [tex]\int[/tex] suggested.

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

[tex] ax^2 + bx +c =0 [/tex]

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.
 
  • #6
Integral said:
You need to but your quadratic in the standard form

[tex] ax^2 + bx +c =0 [/tex]

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

[tex] r^2 = x^2 + y^2 [/tex]
[tex] r^2 = x^2 + (mx+b)^2 [/tex]
[tex] r^2 = x^2 + mx^2 + 2*bmx + b^2 [/tex]

I have no idea how I can get that to [tex] ax^2 + bx +c =0 [/tex]
 
  • #7
[tex]r^2=x^2+mx^2+2bmx+b^2=(1+m)x^2+(2bm)x+b^2[/tex]

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.
 
  • #8
ZioX said:
[tex]r^2=x^2+mx^2+2bmx+b^2=(1+m)x^2+(2bm)x+b^2[/tex]

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 [tex]x^2 + mx^2 = (1+m)x^2[/tex]

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 :tongue:

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

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

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

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

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

Is this right?
 
Last edited:

1. What is an intersection point of a line on a circle?

An intersection point of a line on a circle is a point where the line and the circle meet or touch each other. It is the point where the line intersects the circumference of the circle.

2. How many intersection points can a line have with a circle?

A line can have a maximum of two intersection points with a circle. This is because a line can only intersect a circle at two points, unless the line is a tangent to the circle, in which case it will have only one intersection point.

3. What is the relationship between the slope of a line and the intersection points with a circle?

The slope of a line and the intersection points with a circle are related by the fact that a line with a positive slope will intersect a circle at two points, while a line with a negative slope will also intersect a circle at two points. However, if the line is horizontal or vertical, it will only intersect the circle at one point.

4. How do you find the coordinates of the intersection points between a line and a circle?

To find the coordinates of the intersection points between a line and a circle, you need to solve the equations of both the line and the circle simultaneously. This can be done by substituting the equation of the line into the equation of the circle and solving for the coordinates of the intersection points.

5. Can a line intersect a circle at more than two points?

No, a line can only intersect a circle at a maximum of two points. This is because a circle is a two-dimensional shape and a line is a one-dimensional object, so they can only intersect at a maximum of two points.

Similar threads

  • Precalculus Mathematics Homework Help
Replies
5
Views
917
  • Precalculus Mathematics Homework Help
Replies
23
Views
1K
  • Precalculus Mathematics Homework Help
Replies
18
Views
1K
  • Precalculus Mathematics Homework Help
Replies
5
Views
2K
  • Precalculus Mathematics Homework Help
Replies
17
Views
1K
  • Precalculus Mathematics Homework Help
Replies
3
Views
1K
  • Precalculus Mathematics Homework Help
Replies
9
Views
2K
  • Precalculus Mathematics Homework Help
Replies
14
Views
1K
Replies
4
Views
786
  • Precalculus Mathematics Homework Help
Replies
5
Views
1K
Back
Top