BAEL-2151
This commit is contained in:
myluckagain
2018-08-30 03:56:21 +05:00
committed by Predrag Maric
parent 2274e39392
commit 2a12e9abd4
2 changed files with 61 additions and 0 deletions
@@ -0,0 +1,21 @@
package com.baeldung.linesintersection;
import java.awt.Point;
import java.util.Optional;
public class LinesIntersectionService {
public Optional<Point> calculateIntersectionPoint(float m1, float b1, float m2, float b2) {
if (m1 == m2) {
return Optional.empty();
}
float x = (b2 - b1) / (m1 - m2);
float y = m1 * x + b1;
Point point = new Point(Math.round(x), Math.round(y));
return Optional.of(point);
}
}