opt
This commit is contained in:
@@ -16,6 +16,22 @@ public class PointInterpolatorUtil {
|
||||
private static final String TAG = "PointInterpolatorUtil";
|
||||
private static final int DISTANCE_THRESHOLD = 2;
|
||||
|
||||
/**
|
||||
* 在(x1,y1) (x2,y2)中间插入一些点,使每两个点之间距离<={@link #DISTANCE_THRESHOLD},利用如下公式进行计算
|
||||
* xn = x1 + (x2 - x1)*n/a
|
||||
* yn = y1 + (y2 - y1)*n/a
|
||||
* a = (distance/{@link #DISTANCE_THRESHOLD}) +1
|
||||
* n in 1 .. a-1
|
||||
* n == 0 时,xn = x1
|
||||
* n == a 时,xn = x2
|
||||
*
|
||||
* 将xn依次插入x1到x2之间
|
||||
*
|
||||
* @param points 待插值点集
|
||||
*
|
||||
* @deprecated 这个方法有问题,并不能算出来想要的值
|
||||
*/
|
||||
@Deprecated
|
||||
public static void interpolate(List<MogoLatLng> points) {
|
||||
if (points.size() >= 2) {
|
||||
// 插值
|
||||
@@ -25,10 +41,10 @@ public class PointInterpolatorUtil {
|
||||
float distance = CoordinateUtils.calculateLineDistance(current.lon, current.lat, next.lon, next.lat);
|
||||
Logger.d(TAG, i + ": " + distance);
|
||||
if (distance > DISTANCE_THRESHOLD) {
|
||||
int inter = (int) (distance / DISTANCE_THRESHOLD);
|
||||
for (int j = 0; j < inter; j++) {
|
||||
double newLat = current.lat + (next.lat - current.lat) * 2 * (j + 1) / distance;
|
||||
double newLon = current.lon + (next.lon - current.lon) * 2 * (j + 1) / distance;
|
||||
int inter = (int) (distance / DISTANCE_THRESHOLD) + 1;
|
||||
for (int j = 1; j < inter; j++) {
|
||||
double newLat = current.lat + (next.lat - current.lat) * j / inter;
|
||||
double newLon = current.lon + (next.lon - current.lon) * j / inter;
|
||||
Logger.d(TAG, "distance: " + distance + ", j: " + j + ", nextLat: " + next.lat + ", nextLon: " + next.lon + ", newLat: " + newLat + ", newLon: " + newLon);
|
||||
points.add(i + 1, new MogoLatLng(newLat, newLon));
|
||||
current = points.get(++i);
|
||||
@@ -39,7 +55,7 @@ public class PointInterpolatorUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static double[] mergeToRoad(double lon, double lat, List< LonLatPoint > road) {
|
||||
public static double[] mergeToRoad(double lon, double lat, List<LonLatPoint> road) {
|
||||
closeStart = 0;
|
||||
closeEnd = road.size() - 1;
|
||||
getCloseTwoPoint(lon, lat, road);
|
||||
@@ -76,7 +92,7 @@ public class PointInterpolatorUtil {
|
||||
double u = (lat - beginPt.getLatitude()) * (beginPt.getLatitude() - endPt.getLatitude()) +
|
||||
(lon - beginPt.getLongitude()) * (beginPt.getLongitude() - endPt.getLongitude());
|
||||
u = u / (dx * dx + dy * dy);
|
||||
return new double[]{ beginPt.getLongitude() + u * dy, beginPt.getLatitude() + u * dx};
|
||||
return new double[]{beginPt.getLongitude() + u * dy, beginPt.getLatitude() + u * dx};
|
||||
}
|
||||
|
||||
private static double[] getMid(LonLatPoint start, LonLatPoint end) {
|
||||
|
||||
Reference in New Issue
Block a user