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.
62 lines
1.9 KiB
62 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 CompoundMark extends Marker{
|
|
|
|
private GPSCoordinate averageGPSCoordinate;
|
|
private Mark mark1;
|
|
private Mark mark2 = null;
|
|
|
|
public CompoundMark(Mark mark1) {
|
|
super(mark1.getPosition());
|
|
this.mark1 = mark1;
|
|
this.averageGPSCoordinate = calculateAverage();
|
|
|
|
}
|
|
|
|
public CompoundMark(Mark mark1, Mark mark2) {
|
|
super(mark1.getPosition(), mark2.getPosition());
|
|
this.mark1 = mark1;
|
|
this.mark2 = mark2;
|
|
this.averageGPSCoordinate = calculateAverage();
|
|
|
|
}
|
|
|
|
public Mark getMark1Source() { return mark1; }
|
|
|
|
public Mark getMark2Source() { return mark2; }
|
|
|
|
public GPSCoordinate getMark1() {
|
|
return mark1.getPosition();
|
|
}
|
|
|
|
public GPSCoordinate getMark2() {
|
|
return mark2.getPosition();
|
|
}
|
|
|
|
public GPSCoordinate getAverageGPSCoordinate() {
|
|
return averageGPSCoordinate;
|
|
}
|
|
|
|
private GPSCoordinate calculateAverage() {
|
|
if(mark2 != null) {
|
|
GeodeticCalculator calc = new GeodeticCalculator();
|
|
calc.setStartingGeographicPoint(mark1.getPosition().getLongitude(), mark1.getPosition().getLatitude());
|
|
calc.setDestinationGeographicPoint(mark2.getPosition().getLongitude(), mark2.getPosition().getLatitude());
|
|
double azimuth = calc.getAzimuth();
|
|
double distance = calc.getOrthodromicDistance();
|
|
|
|
GeodeticCalculator middleCalc = new GeodeticCalculator();
|
|
middleCalc.setStartingGeographicPoint(mark1.getPosition().getLongitude(), mark1.getPosition().getLatitude());
|
|
middleCalc.setDirection(azimuth, distance / 2);
|
|
Point2D middlePoint = middleCalc.getDestinationGeographicPoint();
|
|
return new GPSCoordinate(middlePoint.getY(), middlePoint.getX());
|
|
} else return mark1.getPosition();
|
|
}
|
|
}
|