generated from wpilibsuite/vendor-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Trianlg and Point classes to geometry
- Loading branch information
1 parent
47cb5a2
commit 8d2915d
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
} | ||
} |