Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.56 KB | None | 0 0
  1. Point intersection(Segment another) {
  2.         double den = ((this.startX - this.endX) * (another.startY - another.endY) - (this.startY - this.endY) * (another.startX - another.endX)); //знаменатель
  3.         double a = (this.startX * this.endY - this.startY * this.endX); //x1y2 - y1x2
  4.         double b = (another.startX * another.endY - another.startY * another.endX); //x3y4 -y3x4
  5.         double pointx = ((a * (another.startX - another.endX)) - b * (this.startX - this.endX)) / den; //X
  6.         double pointy = ((a * (another.startY - another.endY)) - b * (this.startY - this.endY)) / den; //Y
  7.  
  8.         Point answer = new Point(pointx, pointy);
  9.         //проверка
  10.         boolean f1 = (((this.endX <= answer.getX()) && (answer.getX() <= this.startX)) || ((this.startX <= answer.getX()) && (answer.getX() <= this.endX)));
  11.         boolean f2 = (((this.endY <= answer.getY()) && (answer.getY() <= this.startY)) || ((this.startY <= answer.getY()) && (answer.getY() <= this.endY)));
  12.         boolean f3 = (((another.endX <= answer.getX()) && (answer.getX() <= another.startX)) || ((another.startX <= answer.getX()) && (answer.getX() <= another.endX)));
  13.         boolean f4 = (((another.endY <= answer.getY()) && (answer.getY() <= another.startY)) || ((another.startY <= answer.getY()) && (answer.getY() <= another.endY)));
  14.  
  15.             if ((f1 && f2 && f3 && f4) != false && den != 0 &&  ) {
  16.                 return answer;
  17.             }
  18. //            if () {
  19. //                throw new NullPointerException();
  20. //            }
  21.  
  22.         else return null;
  23.  
  24.  
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement