所以这是我的解决方案。我们决定二维投影的“中心”应该是相对的。它确实适合我们的任务。以下是一些代码示例:
public final class GeometryUtil {
/**
https://www.cfa.harvard.edu/~dfabricant/huchra/ay145/constants.html
1 Earth Radius = 6.37814x108 cm = 6.37814x10^6 m (Equatorial)
*/
public static final double EARTH_RADIUS_IN_METERS = 6.37814e+6;
private GeometryUtil(){}
/**
* @param geoPoint is a point of some object you want to translate to Cartesian.
* @param geoPointRelative is a point of relative center.
* We suppose that this relative GeoPoint is a center for the first parameter.
* */
public static Coordinate toCoordinate(GeoPoint geoPoint, GeoPoint geoPointRelative){
return new Coordinate(toX(geoPoint, geoPointRelative.getLongitude()),
toY(geoPoint, geoPointRelative.getLatitude()));
}
public static double toX(GeoPoint geoPoint, double relativeLongitude){
return EARTH_RADIUS_IN_METERS *
cos(toRadians(geoPoint.getLatitude())) *
toRadians(geoPoint.getLongitude()- relativeLongitude);
}
public static double toY(GeoPoint geoPoint, double relativeLatitude){
return EARTH_RADIUS_IN_METERS * toRadians(geoPoint.getLatitude() - relativeLatitude);
}
}
这是几何图形的构建器:
public final class GeometryBuilder {
private static final int DIAMETER_MULTIPLIER = 2;
private static final int TURN_LEFT = 90; //We should start to roll to the right from "North"/"Up"/12 o'clock
private GeometryBuilder(){}
public static Circle buildCirlce(GeoPoint centerOfCircle, GeoPoint relativeCenter, Distance radiusDistance){
GeometricShapeFactory geometricShapeFactory = new GeometricShapeFactory();
geometricShapeFactory.setCentre(GeometryUtil.toCoordinate(centerOfCircle, relativeCenter));
geometricShapeFactory.setSize(radiusDistance.getMeters() * DIAMETER_MULTIPLIER);
return new Circle(geometricShapeFactory.createEllipse());
}
public static Sector buildGSMCellSector(GSMCellLocation gsmCellLocation, GeoPoint relativeCenter){
GeometricShapeFactory geometricShapeFactory = new GeometricShapeFactory();
geometricShapeFactory.setCentre(GeometryUtil.toCoordinate(gsmCellLocation.getGeoPoint(), relativeCenter));
geometricShapeFactory.setSize(gsmCellLocation.getMidDist() * DIAMETER_MULTIPLIER);
return new Sector(geometricShapeFactory.createArcPolygon(-toRadians(gsmCellLocation.getEndAngle()- TURN_LEFT),
toRadians(gsmCellLocation.getAngleWidth())));
}
}
我应该提到 TURN_LEFT 是特定的。我的对象的角度从 12 点开始。几何库从 3 点开始计数。这就是为什么我必须将其转回 3 小时(90 度)。
问题已经解决了。我还使用 LiteShape 将一些图像绘制到 PNG 文件中。一切正常。