You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.9 KiB
75 lines
1.9 KiB
package seng302.Model;
|
|
|
|
import org.geotools.referencing.GeodeticCalculator;
|
|
import java.awt.geom.Point2D;
|
|
|
|
/**
|
|
* Created by esa46 on 29/03/17.
|
|
*/
|
|
public class CompoundMarker {
|
|
|
|
private GPSCoordinate averageGPSCoordinate;
|
|
private GPSCoordinate mark1;
|
|
private GPSCoordinate mark2;
|
|
private String name;
|
|
private boolean doubleMarker = false;
|
|
|
|
public CompoundMarker(GPSCoordinate mark1) {
|
|
|
|
this.mark1 = mark1;
|
|
this.mark2 = mark1;
|
|
this.averageGPSCoordinate = calculateAverage();
|
|
|
|
}
|
|
|
|
public CompoundMarker(GPSCoordinate mark1, GPSCoordinate mark2) {
|
|
|
|
this.mark1 = mark1;
|
|
this.mark2 = mark2;
|
|
this.averageGPSCoordinate = calculateAverage();
|
|
|
|
}
|
|
|
|
public CompoundMarker(String name, GPSCoordinate mark1, GPSCoordinate mark2) {
|
|
|
|
this.name = name;
|
|
this.mark1 = mark1;
|
|
this.mark2 = mark2;
|
|
this.averageGPSCoordinate = calculateAverage();
|
|
|
|
}
|
|
|
|
public GPSCoordinate getMark1() {
|
|
return mark1;
|
|
}
|
|
|
|
public GPSCoordinate getMark2() {
|
|
return mark2;
|
|
}
|
|
|
|
public GPSCoordinate getAverageGPSCoordinate() {
|
|
return averageGPSCoordinate;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
private GPSCoordinate calculateAverage() {
|
|
|
|
GeodeticCalculator calc = new GeodeticCalculator();
|
|
calc.setStartingGeographicPoint(mark1.getLongitude(), mark1.getLatitude());
|
|
calc.setDestinationGeographicPoint(mark2.getLongitude(), mark2.getLatitude());
|
|
double azimuth = calc.getAzimuth();
|
|
double distance = calc.getOrthodromicDistance();
|
|
|
|
GeodeticCalculator middleCalc = new GeodeticCalculator();
|
|
middleCalc.setStartingGeographicPoint(mark1.getLongitude(), mark1.getLatitude());
|
|
middleCalc.setDirection(azimuth, distance / 2);
|
|
Point2D middlePoint = middleCalc.getDestinationGeographicPoint();
|
|
return new GPSCoordinate(middlePoint.getY(), middlePoint.getX());
|
|
|
|
}
|
|
|
|
}
|