collision point of circle and line

803 Views Asked by At

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

2

There are 2 best solutions below

1
On BEST ANSWER

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

1
On

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.