Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Point intersection(Segment another) {
- double den = ((this.startX - this.endX) * (another.startY - another.endY) - (this.startY - this.endY) * (another.startX - another.endX)); //знаменатель
- double a = (this.startX * this.endY - this.startY * this.endX); //x1y2 - y1x2
- double b = (another.startX * another.endY - another.startY * another.endX); //x3y4 -y3x4
- double pointx = ((a * (another.startX - another.endX)) - b * (this.startX - this.endX)) / den; //X
- double pointy = ((a * (another.startY - another.endY)) - b * (this.startY - this.endY)) / den; //Y
- Point answer = new Point(pointx, pointy);
- //проверка
- boolean f1 = (((this.endX <= answer.getX()) && (answer.getX() <= this.startX)) || ((this.startX <= answer.getX()) && (answer.getX() <= this.endX)));
- boolean f2 = (((this.endY <= answer.getY()) && (answer.getY() <= this.startY)) || ((this.startY <= answer.getY()) && (answer.getY() <= this.endY)));
- boolean f3 = (((another.endX <= answer.getX()) && (answer.getX() <= another.startX)) || ((another.startX <= answer.getX()) && (answer.getX() <= another.endX)));
- boolean f4 = (((another.endY <= answer.getY()) && (answer.getY() <= another.startY)) || ((another.startY <= answer.getY()) && (answer.getY() <= another.endY)));
- if ((f1 && f2 && f3 && f4) != false && den != 0 && ) {
- return answer;
- }
- // if () {
- // throw new NullPointerException();
- // }
- else return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement