gpt4 book ai didi

java - 将两点创建的面积扩大其距离的百分比

转载 作者:行者123 更新时间:2023-12-02 01:41:12 25 4
gpt4 key购买 nike

我有两个地理点来创建一个盒子(每个点都是一个角)。我想创建一个稍微大一点的盒子。以下代码片段是创建该框的代码。

private Box createRouteBox(DirectionsRoute route){
Box box;
Bounds bounds = route.bounds;

LatLng northeast = bounds.northeast;
LatLng southwest = bounds.southwest;

Point northeastPoint = new Point(northeast.lng, northeast.lat);
Point southwestPoint = new Point(southwest.lng, southwest.lat);

box = new Box(northeastPoint, southwestPoint);

return box;
}

您能给我一个如何继续前进的建议吗?

最佳答案

尝试这样的事情

private Box expandedBox(Point northeastPoint, Point southwestPoint){

// percentage of distance to set as padding to the box
Double offset = 0.1;
Double distance = pointDistance(northeastPoint, southwestPoint);
Double padding = (distance * offset);

// get current x, y
Double neX = northeastPoint.getX();
Double neY = northeastPoint.getY();
Double swX = southwestPoint.getX();
Double swY = southwestPoint.getY();

// init new x, y
Double neX2, neY2, swX2, swY2;


if(neX > swX){
neX2 = neX + padding;
swX2 = swX - padding;
} else {
neX2 = neX - padding;
swX2 = swX + padding;
}

if(neY > swY){
neY2 = neY + padding;
swY2 = swY - padding;
} else {
neY2 = neY - padding;
swY2 = swY + padding;
}

northeastPoint = new Point(neX2, neY2);
southwestPoint = new Point(swX2, swY2);

return new Box(northeastPoint, southwestPoint);
}

private Double pointDistance(Point p1, Point p2) {
return Math.sqrt((p2.getY() - p1.getY()) * (p2.getY() - p1.getY()) + (p2.getX() - p1.getX()) * (p2.getX() - p1.getX()));
}

您可以将偏移更改为所需距离的百分比。

关于java - 将两点创建的面积扩大其距离的百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54439688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com