0
$\begingroup$

I'm trying to figure out the collision point of the circle and a line, ultimately it should work in 3D but for now just in 2D to simplify the problem as much as possible.

I've created 2 examples here on what I'm trying to achieve, I want to find point B and D and it should work both the examples below.

PS. this problem is probably harder to solve than it initially looks like.

Example 1: example1

//edit Radius = 50;

A.x = 70

A.y = 100

B.x = ?

B.y = ?

C.x = -60

C.y = -70

D.x = ?

D.y = ?

E.x = -200

E.y = 0

F.x = 200

F.y = 0

AC_vector = [-130, -170] ---> (= C-A = [((-60)-70), ((-70)-100)] )

AC_distance = 214.009 ---> = √((A.x - C.x)^2 + (A.y - C.y)^2) = sqrt((70 - -60)^2 + (100 - -70)^2)

AC_vectorN = [-0.607451, -0.794359] ---> = AC_vector/AC_distance = [-130/214.009, -170/214.009] // AC_vector normalized

EF_vector = [400, 0] ---> = ( E-F = [(200-(-200)), ((0-0)] )

EF_distance = 400 ---> = √((E.x - F.x)^2 + (E.y - F.y)^2) = sqrt((-200 - 200)^2 + (0 - 0)^2)

EF_vectorN = [1, 0] ---> = EF_vector/EF_distance = [400/400, 0/400] // EF_vector normalized

N = [0, 1] // (surface normal) perpendicular vector of normalized EF

Example 2 example 2

Solution:

Edit// This is what I have figured out so far:

  • The distance between B and D is always the radius (50)

  • The vector of BD is the normal of EF (90deg rotaition of EFvector)

  • So B = D + N*R?

Last part of the solution can be found here: right triangle in 3D space, vectors, line intersection?

And here is the result of the solution: https://youtu.be/1MiwtA329tQ

solution_02

$\endgroup$
  • $\begingroup$ What is a collision point of a circle and a line? $\endgroup$ – Bernard Jan 6 '16 at 19:44
  • $\begingroup$ @Bernard that would be point D in my example images, the reason I call it collision point is because I'm going to use it for a physics engine , and point A is the current position and point C is the projected position after the velocity have been applied and if it detect an intersection then I want to figure out where it collided (point D) so I can place it at the correct position (point B) before I reflect the velocity etc. $\endgroup$ – Patrik Fröhler Jan 6 '16 at 19:49
  • $\begingroup$ Do you have the equations of line and circle at any point in time? Do you have the circle path time line? I can envision at least two ways to solve this. Do you assume that the line is y=0? What is r of the circle? $\endgroup$ – Moti Jan 6 '16 at 19:54
  • $\begingroup$ Looks like B coordinates are (?,r) - right? $\endgroup$ – Moti Jan 6 '16 at 20:00
  • $\begingroup$ @Moti all the values I have are in the two images the radius is 50 its in the green circle, I just forgot to add it in the text, when i'm actually implementing it I have acces to a lot of functions so alot of these values I dont have to calculate like the normal of the EF line i just get that by raytracing and have functions for normalizing etc $\endgroup$ – Patrik Fröhler Jan 6 '16 at 20:03
1
$\begingroup$

See the picture that complements the comment. Thought this could help. Point G (red) is the center of the disc at collision. remember to select the proper collision point - there are two.

enter image description here

$\endgroup$
  • $\begingroup$ Thanks, tough not sure that I solved it 100% like the way you sugested but either way your solution help me to get to my final solution, so thanks. $\endgroup$ – Patrik Fröhler Jan 7 '16 at 23:36
1
$\begingroup$

Here is the equation of a line passing through two points $(x_1,y_1)$ and $(x_2,y_2)$

$$ (y_1-y_2) x + (x_2-x_1) y + (x_1 y_2 - x_2 y_1 ) = 0 $$

A parallel offset to this line with a perpendicular distance $d$ is

$$ (y_1-y_2) x + (x_2-x_1) y + \left(x_1 y_2 - x_2 y_1 -d \sqrt{(x_2-x_1)^2+(y_2-y_1)^2} \right) = 0$$

All you need to do is find the offset line to EF that passes through the center of the circle. This is done by offsetting with the circle radius amount

pic

Then you have two lines that you need to find where they intersect. If the offset line is $A x+ B y + C =0$ and the CA line is $P x + Q y + W = 0$ then their intersection is located at

$$ (x,y) = \left( \frac{B\, W-C\, Q}{A\, Q-B\, P}, \frac{C\, P-A\, W}{A\, Q-B\, P} \right) $$

NOTE: If the denominator is zero the lines are parallel

So the process is

  1. Use the first equation to find the coefficients $(P,Q,W)$ for the line AC
  2. Use the second equation to find the coefficients $(A,B,C)$ for the line EF and offset $d=\mbox{(radius)}$
  3. Use the third equation to find the coordinates for the center of the circle.
$\endgroup$
  • $\begingroup$ Thanks, tough I were able to solve it just a few minutes earlier, but thanks anyways this information will be usfull in the future (: $\endgroup$ – Patrik Fröhler Jan 7 '16 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.