3

I'm trying to develop a simulation in C#, and I have to find the intersection (or collision) point of two moving circles, in 2D space.

Actually one of my circles will be stationary, so only one of them will be moving (linearly, i.e. constant velocity)

So I have two circles with radii R1 and R2, and center points P1 and P2, and the point P1 is changing with constant velocity V1, so I need a way to determine at which point will they collide, also to check if they will collide at all.

Thanks for any help !

Edit :

For the checking (if they will collide) part, I think we can do it by simply calculating the shortest distance between the first circle's velocity line, and the second circle's center, and checking if the distance is greater than R1+R2, so the only thing remains is to find the collision point.

So the question is :

I am assuming the circles will collide, and I need an expression for the collision point P, in terms of P1, P2, R1, R2 and V1.

jeff
  • 225

4 Answers4

3
  1. Find the position of both centers at the time of collision. The position $P_1(t) = p_0 + V_1 t$ defines a line parametrized in $t$. You can then compute the distance $d(P_1(t),P_2)$ between the centers and solve for $d(P_1,P_2) = R_1 + R_2$. You will want to take the solution that is the lowest value of $t$ (when they first collide, rather than when they stop colliding). This will give you the position of $P_1$ at the moment of collision by plugging in your value of $t$.
  2. Find the point of collision based on the center positions at collision time. Given $P_1$ and $P_2$ at collision time, $\frac{R_2}{R_1+R_2}P_1 + \frac{R_1}{R_1+R_2} P_2$ will be the point of collision.
Paul Orland
  • 7,138
  • Thanks, but please note that the collision point is on the surfaces of both circles, so it is not the center of circle 1. Also I would really appreciate a full solution. – jeff Aug 29 '14 at 20:18
  • Given two centers $P1$ and $P_2$, find the line connecting them, and find a point a distance of $R_1$ from $P_1$ on that line. – Paul Orland Aug 29 '14 at 20:53
  • But Circle1 is not necessarily moving towards the center of C2, so the line connecting the two may not be the velocity direction. – jeff Aug 29 '14 at 20:54
  • updated my answer to be more explicit. – Paul Orland Aug 29 '14 at 21:44
1

Let $P_2=(0,0)$ be the origin of the coordinate system as well as the center of the second stationary circle. Let $P_1(t)=(x(t),y(t))$ be the center of the first moving circle and $P_1(0)=(x(0),y(0))=(r \cos\phi,r \sin\phi)$. Let velocity $v=(v_1 \cos\theta,v_1 \sin\theta)$ be the velocity of $P_1(t)$.

Then we have

$$x(t)=r \cos \phi+v_1 t\cos\theta, y(t)=y_0+v_1 t\sin\theta \tag{1}$$

When two circles touching we have:

$$x^2(t)+y^2(t)=(R_1+R_2)^2 \tag{2}$$

You can then convert (2) to:

$$ a t^2+b t +c=0 \tag{3}$$

If $b^2-4 a c \lt 0$, then these two circles never collide.

If $b^2-4 a c \ge 0$, then two circles will collide.

Solve (3) we obtain:

$$t_{\pm}=-\frac{r}{v_1} \cos(\theta-\phi)\pm \frac{\sqrt{2}}{2v_1}\left(2(R_1+R_2)^2-r^2+r^2\cos(2(\theta-\phi))\right)^{1/2}\tag{4}$$

The collision point, call it $C(t)=(X(t),Y(t))$ is half way between $P_2=(0,0) $ and $P_1(t)$.

$$C_1(t_{\pm})= (X(t_{\pm}),X(t_{\pm}))=(1/2)(r \cos \phi+v_1 t_{\pm}\cos\theta,r \sin \phi+v_1 t_{\pm}\sin\theta) \tag{5}$$

Notice that the angle of the velocity $v$ is important. For example, if the radius for both circles are 1. P_1(0)=(10,0) i.e., circle 1 initial position is on the right hand side of circle 2. Let $\theta =\pi/2$, it means that circle 1 is moving up along the y axis. Then circle 1 will never touch circle 2.

mike
  • 5,692
  • Thanks but I mentioned in my edit, that I don't need the collision check part, I assume the collision will occur, and I want the expression for the collision point. – jeff Aug 29 '14 at 20:16
1

Let us say that the moving circle (#1) at time $t$ is located at $({L_{1,x}+t·V_{1,x}}\mid{L_{1,y}+t·V_{1,y}})$ and has radius $r_1$. And, further, the fixed circle (#2) is located at $({L_{2,x}}\mid{L_{2,y}})$ and has radius $r_2$. (The $L$s and $V$s are location components and velocity components, respectively.)

Set up the quadratic equation $(L_{1,x}+t·V_{1,x}-L_{2,x})^2+(L_{1,y}+t·V_{1,y}-L_{2,y})^2 ={(r_1+r_2)^2}$ and solve for $t$. What this equation is saying is, "The square of the distance between the circle centers is, for some value of $t$, equal to the square of the sum of the circles' radii." Your task: Find that value of $t$.
(i) If the $t$s are complex, a collision did not, and will not, occur.
(ii) If the $t$s are real and negative, then the moving circle is coming FROM a collision with the fixed circle. There will be two negative values, the greater of the two showing when this past collision occurred.
(iii) If the $t$s are real and positive, then the moving circle is proceeding TO a collision. There will be two positive values, of which the only useful value is the lesser of the two. (Think about it.) Substitute that value of $t$ into the expression for the two components for the moving circle's center -- and there you are.

(Added later:)   Moreover, if it is desired to impart motion to circle #2, to do so is quite simple: Merely incorporate in the coördinates for circle #2 components of motion just as in circle #1.

@Jyrki Lahtonen \ Thank you, my friend. I thought about your condition (iv) and could not see how it could occur without the between-centers distance starting out as less than the sum of the radii; so, you're right.

  • The approach is sound (+1). I just feel like pointing out that the scene is markedly different, if one circle is completely inside the other. This is probably not a problem in a 2D-simulation. For that to happen the circles would need to be created that way. Also, it may be that (iv) of the solutions $t_1<0$ and $t_2>0$ meaning that currently the circles are moving through each other - another physically non-sensical possibility. – Jyrki Lahtonen Aug 30 '14 at 06:54
1

Based on your edited question, I assume you have computed the distance between $P_2$ and the nearest point on the path of $P_1$ (the point of closest approach). Let $d_1$ denote that distance. I assume you have determined that $d_1 < R_1 + R_2.$ I also assume you have coordinates for $P_2$ and $P_1(0),$ where $P_1(0)$ denotes the initial position of $P_1.$

Let $d_0$ denote the distance between $P_1(0)$ and $P_2.$ Let $A$ be the closest point of approach and let $s_A$ denote the distance from $P_1(0)$ to $A.$ The triangle with vertices $P_1(0),$ $A,$ and $P_2$ is a right triangle, and $s_A$ can be found by the Pythagorean Theorem:

$$ s_A = \sqrt{d_0^2 - d_1^2}.$$

Let $B$ be the location of $P_1$ at the moment of collision and let $s_{AB}$ be the distance between $A$ and $B.$ The distance between $P_2$ and $B$ is $R_1 + R_2,$ and $\triangle BAP_2$ is a right triangle. Then (again using the Pythagorean Theorem)

$$ s_{AB} = \sqrt{(R_1 + R_2)^2 - d_1^2}.$$

The distance from $P_1(0)$ to $B$ is $s_B = s_A - s_{AB},$ so now you merely need to construct a vector in the same direction as $V_1$ with length $s_B$ --that is, compute the vector $\dfrac{s_B}{\|V_1\|} V_1$-- and add that vector's coordinates to the coordinates of $P_1(0).$ This gives you the coordinates of $B.$

But you wanted the point $P$ where the circles touch. If $W$ is the vector from $P_2$ to $B,$ then $\dfrac{R_2}{R_1 + R_2} W$ is the vector from $P_2$ to $P,$ so you just need to add the coordinates of $\dfrac{R_2}{R_1 + R_2} W$ to the coordinates of $P_2,$ and the result is the coordinates of the point you want.

David K
  • 108,155
  • Thanks, David! Your assumptions are correct. I will gather my head and try to understand the rest of your explanation, it looks very accurate though. – jeff Aug 30 '14 at 11:49