• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Point of collision between Shapes

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic