Skip to content

Commit

Permalink
add Trianlg and Point classes to geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
linglejack06 committed Aug 19, 2024
1 parent 47cb5a2 commit 8d2915d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions geometry/src/main/java/coppercore/FieldFinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package coppercore.geometry

import java.awt.geom.Line2D

public class FieldFinder {

}
17 changes: 17 additions & 0 deletions geometry/src/main/java/coppercore/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Point {
private double x;
private double y;

public Point (double x, double y) {
this.x = x;
this.y = y;
}

public double getX () {
return x;
}

public double getY () {
return y;
}
}
25 changes: 25 additions & 0 deletions geometry/src/main/java/coppercore/Triangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class Triangle {
private Point p1, p2, p3;

public Triangle (Point p1, Point p2, Point p3) {
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
}

public boolean isPointInside (Point point) {
Triangle t1 = this(point, p2, p3)
Triangle t2 = this(p1, point, p3)
Triangle t3 = this(p1, p2, point)

double area = this.getArea()

double sumOfT = t1.getArea() + t2.getArea(0 + t3.getArea())

return Math.abs(sumOfT - area) < 0.05
}

public double getArea () {
return 0.5 * Math.abs(p1.getX() * (p2.getY() - p3.getY()) + p2.getX() * (p3.getY() - p1.getY()) + p3.getX() * (p1.getY() - p2.getY()))
}
}

0 comments on commit 8d2915d

Please sign in to comment.