mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
1cac7cc189
Can accurately calculate if a boat is going upwind or downward using a line function for the wind vector from the gate and the boat position from the gate. Requires knowledge of the next mark which requires the boat to have passed a mark. This could be fixed by extracting the leg number from the race status packet and mapping these to gates in an initalisation step tags: #story[956]
64 lines
2.2 KiB
Java
64 lines
2.2 KiB
Java
package seng302;
|
|
|
|
import javafx.geometry.Point2D;
|
|
|
|
/**
|
|
* A Class for performing geometric calculations on the canvas
|
|
* Created by wmu16 on 24/05/17.
|
|
*/
|
|
public final class GeometryUtils {
|
|
|
|
|
|
/**
|
|
* Performs the line function on two points of a line and a test point to test which side of the line that point is
|
|
* on. If the return value is
|
|
* return 1, then the point is on one side of the line,
|
|
* return -1 then the point is on the other side of the line
|
|
* return 0 then the point is exactly on the line.
|
|
* @param linePoint1 One point of the line
|
|
* @param linePoint2 Second point of the line
|
|
* @param testPoint The point to test with this line
|
|
* @return A return value indicating which side of the line the point is on
|
|
*/
|
|
public static Integer lineFunction(Point2D linePoint1, Point2D linePoint2, Point2D testPoint) {
|
|
|
|
Double x = testPoint.getX();
|
|
Double y = testPoint.getY();
|
|
Double x1 = linePoint1.getX();
|
|
Double y1 = linePoint1.getY();
|
|
Double x2 = linePoint2.getX();
|
|
Double y2 = linePoint2.getY();
|
|
|
|
Double result = (x - x1)*(y2 - y1) - (y - y1)*(x2 - x1); //Line function
|
|
|
|
if (result > 0) {
|
|
return 1;
|
|
}
|
|
else if (result < 0) {
|
|
return -1;
|
|
}
|
|
else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Given a point and a vector (angle and vector length) Will create a new point, that vector away from the origin
|
|
* point
|
|
* @param originPoint The point with which to use as the base for our vector addition
|
|
* @param angleInDeg (DEGREES) The angle at which our new point is being created (in degrees!)
|
|
* @param vectorLength The length out on this angle from the origin point to create the new point
|
|
* @return a Point2D
|
|
*/
|
|
public static Point2D makeArbitraryVectorPoint(Point2D originPoint, Double angleInDeg, Double vectorLength) {
|
|
|
|
Double endPointX = originPoint.getX() + vectorLength * Math.cos(Math.toRadians(angleInDeg));
|
|
Double endPointY = originPoint.getY() + vectorLength * Math.sin(Math.toRadians(angleInDeg));
|
|
|
|
return new Point2D(endPointX, endPointY);
|
|
|
|
}
|
|
|
|
}
|