Olav Ausland
Olav Ausland

Reputation: 98

Find intersection by knowing a point, direction, circle position and radius (2D)

#Problem

Hey I wondered how we can find the intersection between a point with a vector direction, assuming that the point is in the circle. In Other words, how can I find where the particle will hit the circle circumference when I know the following: Circle position, radius, Particle Position and direction (velocity).

#Implementation

I am currently creating a flight radar, all flights are stored in a Queue and I need to sort the queue based on the time untill the flight leaves the cirlce (Radar Radius) So I need to return a Point, thus I can just get the distance and calculate the time based on distance and velocity.

diagram of the situation

Upvotes: 0

Views: 481

Answers (1)

MBo
MBo

Reputation: 80187

At first subtract center cordinates to simplify calculations (now circle center is coordinate origin)

x11 = x1 - x0
y11 = y1 - y0

Point position against time is

x = x11 + vx * t
y = y11 + vy * t

where vx, vy are components of velocity

Point is at circumference when

x^2 + y^2 = R^2 

so

(x11 + vx * t)^2 + (y11 + vy * t)^2 = R^2
(vx^2+vy^2)*t^2 + (2*vx*x11+2*vy*y11)*t + (x11^2+y11^2-R^2) = 0

This is quadratic equation for unknown t. Solve it, find roots - none for outside moving, one for single touch case, two roots for regular intersection - larger one is needed time of intersection t_int

Substitute t into point position equations and get coordinates:

x_int = x1 + t_int * vx
y_int = y1 + t_int * vy

Upvotes: 2

Related Questions