2 line collision detection in java (Android)

Very simple question. How do you achieve collision detection with lines drawn in Java? Just lines. No rectangles, circles or images, bitmaps .. just lines.

By the way, these lines are not straight lines. They are built of hundreds of very small lines that represent the player’s movement (their GPS coordinates when they move), so they interfere everywhere when the player moves. All lines are connected. The endpoint of one line is the starting point of the next and so on. This is a continuous line in this regard. No spaces.

I tried to store the x, y values ​​of the starting points of the rows in the array and then repeat through this array to determine if this point was previously visited. This is normal if the player visits the exact coordinates again, but what if he is halfway between these recorded points?

This is a background issue if that helps. But the main question is my attention here. How do you achieve string collision detection in Java?

+3
source share
3 answers

, , . , , , . , ( ) .

0

, ( ), ?

, , . , , quadtree.

.

0

, List<Line2D> - . List<Line2D> a List<Line2D> b, b. , , - Line2D . :

for(Line2D line1 : a) {
   for(Line2D line2 : b) {
      if(a.intersectsLine(b)) {
         return true;
      }
   }
}
return false;

, . , - : - .

0

All Articles