forked from next-step/java-coordinate-playground
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTriangle.java
More file actions
35 lines (24 loc) · 804 Bytes
/
Triangle.java
File metadata and controls
35 lines (24 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package Figure;
import domain.Point;
import domain.Points;
public class Triangle implements Calculator {
private Points points;
public Triangle(Points points) {
this.points = points;
}
@Override
public double calculate() {
Point pointA = points.getPoint(0);
Point pointB = points.getPoint(1);
Point pointC = points.getPoint(2);
double area = 0.5 * (
this.getTriangleLine(pointA, pointB, pointC) +
this.getTriangleLine(pointB, pointC, pointA) +
this.getTriangleLine(pointC, pointA, pointB)
);
return Math.abs(area);
}
private int getTriangleLine(Point pointA, Point pointB, Point pointC) {
return pointA.getX() * (pointB.getY() - pointC.getY());
}
}