Trying to get laylines to display on proper respective sides of the gate

Having a great time here, Not quite working. There was an issue where the laylines are crossed and I think its tied to the fact that sometimes the two seperate points of the gate mark appear to have the same x y coordinate so the line function doesnt work? idk

tags: #story[956] #pair[wmu16]
This commit is contained in:
William Muir
2017-05-25 00:22:15 +12:00
parent 3cbbdb070f
commit ffe70a8313
3 changed files with 32 additions and 19 deletions
@@ -22,6 +22,7 @@ import javafx.stage.Stage;
import javafx.stage.StageStyle; import javafx.stage.StageStyle;
import javafx.util.Duration; import javafx.util.Duration;
import javafx.util.StringConverter; import javafx.util.StringConverter;
import seng302.GeometryUtils;
import seng302.controllers.annotations.Annotation; import seng302.controllers.annotations.Annotation;
import seng302.controllers.annotations.ImportantAnnotationController; import seng302.controllers.annotations.ImportantAnnotationController;
import seng302.controllers.annotations.ImportantAnnotationDelegate; import seng302.controllers.annotations.ImportantAnnotationDelegate;
@@ -213,7 +214,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
if (legNumber == 0) { if (legNumber == 0) {
System.out.println("PreStart"); System.out.println("PreStart");
return null; return null;
} else if (legNumber == markSequence.size() - 2) { } else if (legNumber == markSequence.size() - 1) {
System.out.println("Finishing"); System.out.println("Finishing");
return null; return null;
} }
@@ -329,8 +330,17 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
Double resultingAngle = angleAndSpeed.keySet().iterator().next(); Double resultingAngle = angleAndSpeed.keySet().iterator().next();
mg.addLayLine(markPoint1, 180 - resultingAngle, StreamParser.getWindDirection());
mg.addLayLine(markPoint2, 180 - resultingAngle, StreamParser.getWindDirection()); Point2D boatCurrentPos = new Point2D(bg.getLayoutX(), bg.getLayoutY());
Point2D gateMidPoint = markPoint1.midpoint(markPoint2);
Integer lineFuncResult = GeometryUtils.lineFunction(boatCurrentPos, gateMidPoint, markPoint2);
if (lineFuncResult == 1) {
mg.addRightLayline(markPoint2, 180 - resultingAngle, StreamParser.getWindDirection());
mg.addLeftLayline(markPoint1, 180 - resultingAngle, StreamParser.getWindDirection());
} else if (lineFuncResult == -1) {
mg.addRightLayline(markPoint1, 180 - resultingAngle, StreamParser.getWindDirection());
mg.addLeftLayline(markPoint2, 180 - resultingAngle, StreamParser.getWindDirection());
}
} }
} }
@@ -7,6 +7,7 @@ import javafx.scene.Group;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
import javafx.scene.shape.Line; import javafx.scene.shape.Line;
import seng302.GeometryUtils;
/** /**
* Created by CJIRWIN on 26/04/2017. * Created by CJIRWIN on 26/04/2017.
@@ -52,27 +53,27 @@ public class MarkGroup extends Group {
return new Point2D(newX, newY); return new Point2D(newX, newY);
} }
/**
* Adds a lay-line to the MarkGroup
* @param startPoint The mark where the lay line starts
* @param layLineAngle The angle the laylines point
* @param baseAngle The reference angle
*/
public void addLayLine(Point2D startPoint, Double layLineAngle, Double baseAngle){
Point2D ep1 = getPointRotation(startPoint, 50.0, baseAngle + -layLineAngle); public void addLeftLayline(Point2D startPoint, Double layLineAngle, Double baseAngle) {
Point2D ep2 = getPointRotation(startPoint, 50.0, baseAngle + layLineAngle);
Line line1 = new Line(startPoint.getX(), startPoint.getY(), ep1.getX(), ep1.getY()); Point2D ep = getPointRotation(startPoint, 50.0, baseAngle + layLineAngle);
Line line2 = new Line(startPoint.getX(), startPoint.getY(), ep2.getX(), ep2.getY()); Line line = new Line(startPoint.getX(), startPoint.getY(), ep.getX(), ep.getY());
line.setStrokeWidth(1);
line.setStroke(Color.GREEN);
line1.setStrokeWidth(0.5); super.getChildren().addAll(line);
line1.setStroke(Color.GREEN);
line2.setStrokeWidth(0.5); }
line2.setStroke(Color.GREEN);
public void addRightLayline(Point2D startPoint, Double layLineAngle, Double baseAngle) {
Point2D ep = getPointRotation(startPoint, 50.0, baseAngle - layLineAngle);
Line line = new Line(startPoint.getX(), startPoint.getY(), ep.getX(), ep.getY());
line.setStrokeWidth(1);
line.setStroke(Color.GREEN);
super.getChildren().addAll(line);
super.getChildren().addAll(line1, line2);
} }
public MarkGroup(GateMark mark, Point2D points1, Point2D points2) { public MarkGroup(GateMark mark, Point2D points1, Point2D points2) {
@@ -427,6 +427,8 @@ public class StreamParser extends Thread{
})); }));
} }
markPositions.get(boatId).put(markPacket); markPositions.get(boatId).put(markPacket);
} }
} }