Moved the canvas drawing implementation from team27's codebase to team13's.

#story30b
This commit is contained in:
Calum
2017-04-20 19:06:32 +12:00
parent 15ded667fe
commit b5129c5c80
7 changed files with 323 additions and 99 deletions
@@ -16,8 +16,8 @@ public class GateMark extends Mark {
* @param singleMark1 one single mark inside of the gate mark
* @param singleMark2 the second mark inside of the gate mark
*/
public GateMark(String name, SingleMark singleMark1, SingleMark singleMark2, double latitude, double longitude) {
super(name, MarkType.GATE_MARK, latitude, longitude);
public GateMark(String name, MarkType type, SingleMark singleMark1, SingleMark singleMark2, double latitude, double longitude) {
super(name, type, latitude, longitude);
this.singleMark1 = singleMark1;
this.singleMark2 = singleMark2;
}
@@ -47,4 +47,16 @@ public class GateMark extends Mark {
//return (this.getSingleMark1().getLongitude() + this.getSingleMark2().getLongitude()) / 2;
return (this.getSingleMark1().getLongitude());
}
public void assignXYCentered () {
System.out.println("POSSIBLE GOOF " + xValue + " " + yValue);
System.out.println(singleMark1.getX() + " " + singleMark1.getY());
System.out.println(singleMark2.getX() + " " + singleMark2.getY());
double dx = singleMark2.getX() - singleMark1.getX();
System.out.println("dx + " + dx);
double dy = singleMark2.getY() - singleMark1.getY();
xValue = (int) Math.round(singleMark1.getX() + dx / 2);
yValue = (int) Math.round(singleMark1.getY() + dy / 2);
System.out.println("PROBABLE GAAF " + xValue + " " + yValue);
}
}
@@ -10,6 +10,8 @@ public abstract class Mark {
private MarkType markType;
private double latitude;
private double longitude;
Integer xValue;
Integer yValue;
/**
* Create a mark instance by passing its name and type
@@ -28,6 +30,76 @@ public abstract class Mark {
this.longitude = longitude;
}
/**
* Calculated the heading in radians from first Mark to the second Mark.
*
* @param pointOne First Mark
* @param pointTwo Second Mark
* @return Heading in radians
*/
public static Double calculateHeadingRad(Mark pointOne, Mark pointTwo) {
Double longitude1 = pointOne.getLongitude();
Double longitude2 = pointTwo.getLongitude();
Double latitude1 = pointOne.getLatitude();
Double latitude2 = pointTwo.getLatitude();
return calculateHeadingRad(longitude1, longitude2, latitude1, latitude2);
}
/**
* Calculate the heading in radians from geographical location with latitude1, longitude 1 to geographical
* latitude2, longitude 2
* @param longitude1 Longitude of first point in degrees
* @param longitude2 Longitude of second point in degrees
* @param latitude1 Latitude of first point in degrees
* @param latitude2 Latitude of first point in degrees
* @return Heading in radians
*/
public static double calculateHeadingRad (Double longitude1, Double longitude2, Double latitude1, Double latitude2) {
latitude1 = Math.toRadians(latitude1);
latitude2 = Math.toRadians(latitude2);
Double longDiff= Math.toRadians(longitude2-longitude1);
Double y = Math.sin(longDiff)*Math.cos(latitude2);
Double x = Math.cos(latitude1)*Math.sin(latitude2)-Math.sin(latitude1)*Math.cos(latitude2)*Math.cos(longDiff);
return Math.atan2(y, x);
}
/**
* Calculates the distance in meters from the first Mark to a second Mark
*
* @param pointOne First Mark
* @param pointTwo Second Mark
* @return Distance in meters
*/
public static Double calculateDistance(Mark pointOne, Mark pointTwo) {
Double longitude1 = pointOne.getLongitude();
Double longitude2 = pointTwo.getLongitude();
Double latitude1 = pointOne.getLatitude();
Double latitude2 = pointTwo.getLatitude();
return calculateDistance(longitude1, longitude2, latitude1, latitude2);
}
/**
* Calculate the distance in meters from geographical location with latitude1, longitude 1 to geographical
* latitude2, longitude 2
*
* @param longitude1 Longitude of first point in degrees
* @param longitude2 Longitude of second point in degrees
* @param latitude1 Latitude of first point in degrees
* @param latitude2 Latitude of first point in degrees
* @return Distance in meters
*/
public static Double calculateDistance (Double longitude1, Double longitude2, Double latitude1, Double latitude2) {
Double theta = longitude1 - longitude2;
Double dist = Math.sin(Math.toRadians(latitude1)) * Math.sin(Math.toRadians(latitude2)) +
Math.cos(Math.toRadians(latitude1)) * Math.cos(Math.toRadians(latitude2)) *
Math.cos(Math.toRadians(theta));
dist = Math.acos(dist);
dist = Math.toDegrees(dist);
dist = dist * 60 * 1.1508; //nautical mile (distance between two degrees) * (degrees in a minute)
dist = dist * 1609.344; //ratio of miles to metres
return dist;
}
public String getName() {
return name;
}
@@ -51,4 +123,21 @@ public abstract class Mark {
public double getLongitude() {
return longitude;
}
public int getX () {
return xValue;
}
public int getY () {
return yValue;
}
public void setX (int x) {
this.xValue = x;
}
public void setY (int y) {
this.yValue = y;
}
}
@@ -5,5 +5,5 @@ package seng302.models.mark;
* Created by Haoming Yin (hyi25) on 17/3/17.
*/
public enum MarkType {
SINGLE_MARK, GATE_MARK
SINGLE_MARK, OPEN_GATE, CLOSED_GATE
}
@@ -65,7 +65,11 @@ public class CourseParser extends FileParser {
String name = element.getElementsByTagName("name").item(0).getTextContent();
SingleMark mark1 = generateSingleMark(element.getElementsByTagName("mark").item(0));
SingleMark mark2 = generateSingleMark(element.getElementsByTagName("mark").item(1));
GateMark gateMark = new GateMark(name, mark1, mark2, mark1.getLatitude(), mark1.getLongitude());
GateMark gateMark;
if (name.equals("Start") || name.equals("Finish"))
gateMark = new GateMark(name, MarkType.CLOSED_GATE, mark1, mark2, mark1.getLatitude(), mark1.getLongitude());
else
gateMark = new GateMark(name, MarkType.OPEN_GATE, mark1, mark2, mark1.getLatitude(), mark1.getLongitude());
marks.put(name, gateMark);
}
}