• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Point of collision between Shapes

 
Davi Teles
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I have a problem in with colissions in JavaFX.

First, i detect a collision between a line and a circle using the follow code:



After this, i need catch the coordinate of collision, like the attach figure.

Anyone knows how catch this coordinate?

[]'s

line_circle_javafx_2.jpg
[Thumbnail for line_circle_javafx_2.jpg]
 
Piet Souris
Rancher
Posts: 1543
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic