Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. public Point getIntersection(Point a, Point b) {
  2.         float d = (x1 - x2) * (a.y - b.y) - (y1 - y2) * (a.x - b.x);
  3.         float newX = ((a.x - b.x) * (x1 * y2 - y1 * x2) - (x1 - x2) * (a.x * b.y - a.y * b.x)) / d;
  4.         float newY = ((a.y - b.y) * (x1 * y2 - y1 * x2) - (y1 - y2) * (a.x * b.y - a.y * b.x)) / d;
  5.  
  6.         return new Point(Math.round(newX), Math.round(newY));
  7.     }
  8.  
  9.     public boolean isInside(Point p) {
  10.         return ((x2 - x1) * (p.y - y1) - (y2 - y1) * (p.x - x1)) < 0;
  11.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement