# Point of collision between Shapes

Davi Teles

Greenhorn

Posts: 1

Piet Souris

Rancher

Posts: 1543

33

posted 1 year ago

hi Davi,

a simple (well, sort of) solution is to write your line as

t * P1 + (1-t) * P2 (1)

with P1 and P2 being the endpoints of the line. The circle has

equation: (x - m1)^2 + (y - m2)^2 = r^2.

Solve these two equations for t.

Now, if there is no value for t, then the line does not intersect the circle

at all. If you find one or two values for t, both outside the interval [0, 1],

then the line does intersect the circle, but the segment between the endpoints

does not.

Finally, if you get one or two t's in the interval [0, 1], then substitute that t or those t's into

equation (1), and then you have your point(s).

This method is far more accurate than working with bounding rectangles.

Greetz,

Piet

a simple (well, sort of) solution is to write your line as

t * P1 + (1-t) * P2 (1)

with P1 and P2 being the endpoints of the line. The circle has

equation: (x - m1)^2 + (y - m2)^2 = r^2.

Solve these two equations for t.

Now, if there is no value for t, then the line does not intersect the circle

at all. If you find one or two values for t, both outside the interval [0, 1],

then the line does intersect the circle, but the segment between the endpoints

does not.

Finally, if you get one or two t's in the interval [0, 1], then substitute that t or those t's into

equation (1), and then you have your point(s).

This method is far more accurate than working with bounding rectangles.

Greetz,

Piet