经纬度演变的轮廓缩放问题?
目标是实现上方的算法(网上的图片)
按照下面的方式进行计算 但并没有达到我的预期(感觉是经纬度转墨卡托出了问题)
public List<com.vividsolutions.jts.geom.Coordinate> warpAndWeft() { //拿到了经纬度
//
List<com.vividsolutions.jts.geom.Coordinate> list = new ArrayList<>();
com.vividsolutions.jts.geom.Coordinate coordinate = new com.vividsolutions.jts.geom.Coordinate(120.0595083689628, 30.313006982475443);
com.vividsolutions.jts.geom.Coordinate coordinate2 = new com.vividsolutions.jts.geom.Coordinate(120.05956464781273, 30.312856394593823);
com.vividsolutions.jts.geom.Coordinate coordinate3 = new com.vividsolutions.jts.geom.Coordinate(120.05976961479806, 30.31289540653132);
com.vividsolutions.jts.geom.Coordinate coordinate4 = new com.vividsolutions.jts.geom.Coordinate(120.05972807069857, 30.313059860492974);
com.vividsolutions.jts.geom.Coordinate coordinate5 = new com.vividsolutions.jts.geom.Coordinate(120.05964635634035, 30.31299054114971);
com.vividsolutions.jts.geom.Coordinate coordinate6 = new com.vividsolutions.jts.geom.Coordinate(120.0595083689628, 30.313006982475443);
list.add(coordinate);
list.add(coordinate2);
list.add(coordinate3);
list.add(coordinate4);
list.add(coordinate5);
list.add(coordinate6);
int size = list.size();
//记录结果
List<com.vividsolutions.jts.geom.Coordinate> result = new ArrayList<>();
for (int i = 0; i < size; i++) {
GeoTransform geoTransform = new GeoTransform();
//将经纬度转变成二维坐标下(采用同高德一致 墨卡托)
com.vividsolutions.jts.geom.Coordinate coordinates = geoTransform.geographic2Mercator(list.get(i));
Point point = new Point();
point.setLongitude(coordinates.x);
point.setLatitude(coordinates.y);
com.vividsolutions.jts.geom.Coordinate coordinates1 = geoTransform.geographic2Mercator(list.get(i == 0 ? size - 1 : i - 1));
Point point1 = new Point();
point1.setLongitude(coordinates1.x);
point1.setLatitude(coordinates1.y);
com.vividsolutions.jts.geom.Coordinate coordinates2 = geoTransform.geographic2Mercator(list.get(i == size - 1 ? 0 : i + 1));
Point point2 = new Point();
point2.setLongitude(coordinates2.x);
point2.setLatitude(coordinates2.y);
//向量pp1
Point sub = VectorUtil.sub(point1, point);//pp1
System.out.println(point1.getLongitude()-point.getLongitude());
double norm = VectorUtil.norm(sub); // |pp1| 膜
double normX1 = sub.getLongitude() / norm; //x向量单位化 v
double normY1 = sub.getLatitude() / norm; //y向量单位化 v
Point pointV3 = new Point(normX1, normY1);
//向量pp2
Point sub2 = VectorUtil.sub(point2, point);//pp2
double norm2 = VectorUtil.norm(sub2); // |pp2| 膜
double normX2 = sub2.getLongitude() / norm2; //x向量单位化 v2
double normY2 = sub2.getLatitude() / norm2; //y向量单位化 v2
Point pointV4 = new Point(normX2, normY2);
//pQ的距离 |pQ| =L / Math.sqrt(1 - (v1x * v2x + v1y * v2y) / 2)
double vectorLen =6 / Math.sqrt((1 - (VectorUtil.cross(pointV3, pointV4))) / 2);
// 根据向量的叉乘积来判断角是凹角还是凸角 (sub.getLongitude() * sub2.getLatitude()) + (-1 * sub.getLatitude() * sub2.getLongitude())
if ((VectorUtil.cross(sub,sub2)) < 0) {
pointV4.setLongitude(-1 * pointV4.getLongitude());
pointV4.setLatitude(-1 * pointV4.getLatitude());
pointV3.setLongitude(-1 * pointV3.getLongitude());
pointV3.setLatitude(-1 * pointV3.getLatitude());
}
//pQ的方向
/* double vectorX = pointV3.getLongitude() + pointV4.getLongitude(); // PQ的向量=v1+v2(向量加 四边形法则)
double vectorY = pointV3.getLatitude() + pointV4.getLatitude(); // PQ的向量=v1+v2(向量加 四边形法则)
Point point3 = new Point(vectorX, vectorY);*/
Point point3 = VectorUtil.add(pointV3, pointV4);
double n = vectorLen / VectorUtil.norm(point3);
double vectorUnitX = n * point3.getLongitude();
double vectorUnitY = n * point3.getLatitude();
//com.vividsolutions.jts.geom.Coordinate coordinate1 = new com.vividsolutions.jts.geom.Coordinate(vectorUnitX, vectorUnitY);
com.vividsolutions.jts.geom.Coordinate coordinate1 = new com.vividsolutions.jts.geom.Coordinate(vectorUnitX+ point.geteLongitude();
, vectorUnitY+point.getLatitude());
System.out.println(coordinate1.toString());
//这里是问题出现的地方,得到计算后的墨卡托坐标后转不回了经纬度 至于为什么转不回还没搞清楚
com.vividsolutions.jts.geom.Coordinate theWarpAndWeftAfterChange = geoTransform.mercator2Geographic(coordinate1);
result.add(theWarpAndWeftAfterChange);
}
return result;
}
结果: 这是不是说明我转墨卡托计算 然后数智超过了计算机的位数(大概这意思:因为我看到了NaN) 那推论 计算后的数值太大所以墨卡托的点转变不会经纬度 这样对吗
[[NaN, NaN], [-2.685147104214853E-5, -4.6804572288379725E-5], [4.539105157497984E-5, -2.9064574458363977E-5], [1.6026060195087032E-5, 5.37608295495793E-5], [-5.2514021949098855E-5, 1.585992833204243E-4], [NaN, NaN]]
回答:
可能是因为你起始点相同,导致起始点的计算涉及到了0的除法,出现了NaN
以上是 经纬度演变的轮廓缩放问题? 的全部内容, 来源链接: utcz.com/p/945059.html