我的任务比较简单,我想请教你。我希望有一个Java库可以帮助我。
描述
鉴于
含义
每个GSM小区由几个扇区组成(它们从一个点开始)。每个对象都表示为一个圆(经度,纬度,半径)。圆圈可以
任务: 我得到了一个GSM小区列表和一个对象。我需要找到一些具有某些扇区的对象的所有感知/触摸。我需要通过拦截方格的结果列表来排序。
看起来像典型的数学/几何任务。 Java中有没有可以帮助我的库?
答案 0 :(得分:0)
1)将所有纬度,lomgitude坐标转换为笛卡尔x,y(米)。 (你可以使用简单的EuqiDistant Projection)搜索这里或wiki,google
2)一旦所有人都在x,y coords,那就是学校数学:
点在圈内? :点与圆心之间的距离<半径
圆点?点在圆内,从点到中心点的角度在扇形方位范围内。
使用
计算从point1到point2的角度angleRad = atan2(dy/dx);
其中dy = p2.y - p1.y
dx analog
答案 1 :(得分:0)
所以这是我的解决方案。 我们认为2D投影的“中心”应该是相对的。它确实适合我们的任务。 以下是一些代码示例:
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文件中。 Everythng没问题。