java求最小外接矩形框

更新时间:2023-07-14 07:46:25 阅读: 评论:0

java求最⼩外接矩形框
import com.hellobike.aiplatform.ba.MPoint;
import lombok.Builder;
import lombok.Data;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class TestMIn {
@Builder
@Data
static class MinRect {
public List<MPoint> minRect;
public double area;
public MinRect(List<MPoint> minRect, double area) {
this.minRect = minRect;
this.area = area;
}
}
public static MinRect getMinRect(List<MPoint> points) {
List<Double> lons = new ArrayList<>();
List<Double> lats = new ArrayList<>();
for (MPoint elem : points) {
荀果lons.Lon());
lats.Lat());
}
double minlon, minlat, maxlon, maxlat;笔记本电脑大全
minlon = Collections.min(lons);
minlat = Collections.min(lats);
maxlon = Collections.max(lons);
maxlat = Collections.max(lats);
MPoint pointa = MPoint.builder().lat(minlat).lon(minlon).build();
MPoint pointb = MPoint.builder().lat(maxlat).lon(maxlon).build();
MPoint pointc = MPoint.builder().lat(maxlat).lon(minlon).build();
MPoint pointd = MPoint.builder().lat(minlat).lon(maxlon).build();
List<MPoint> minRect = new ArrayList<MPoint>();
minRect.add(pointa);
minRect.add(pointb);
minRect.add(pointc);
道德经第三十九章minRect.add(pointd);
double area = (maxlat - minlat) * (maxlon - minlon);
return new MinRect(minRect, area);
}
public static MPoint getSubtra(MPoint pointa, MPoint pointb) {
return new Lon() - Lon(), Lat() - Lat());
}
public static double computeRad(MPoint vector) {
double EPS = 1e-10;
return Math.Lat() / (Lon() + EPS));
}
public static List<MPoint> rotate_poly(List<MPoint> points, double rad) {
double a = s(rad);
double a = s(rad);
double b = Math.sin(rad);
double c = -Math.sin(rad);
double d = s(rad);
List<MPoint> new_points = new ArrayList<>();
for (MPoint point : points) {
new_points.add(new Lon() * a + Lat() * c,
}
分左右return new_points;
}
public static List<MPoint> getPoints(String points_str) {
List<MPoint> points = new ArrayList<>();王者荣耀人物图片
String[] arr = points_str.split(";");决定用英语怎么说
for (String elem : arr) {
String[] point = elem.split(",");
MPoint newPoint = new MPoint();
newPoint.tLon(Double.parDouble(point[0]));
newPoint.tLat(Double.parDouble(point[1]));
points.add(newPoint);
}
return points;
}
public static List<MPoint> getFinalMinRect(String trace) {
List<MPoint> points = getPoints(trace);
/* 计算弧度*/
int points_count = points.size();
List<Double> rad = new ArrayList<>();
rad.add(computeRad((points_count - 1), (0))));
for (int i = 1; i <= points_count - 1; i++) {
rad.add(computeRad((i - 1), (i))));
}
/* 遍历弧度 */
MinRect oldRectObj = getMinRect(points);
List<MPoint> rectMin = MinRect();
double areaMin = Area();
double radMin = 0;
for (double r : rad) {
List<MPoint> new_points = rotate_poly(points, -r);
MinRect newRectObj = getMinRect(new_points);
List<MPoint> rect = MinRect();
双宾动词double area = Area();
if (area < areaMin) {
rectMin = rect;
areaMin = area;
radMin = r;
}
}
塑料怎么做出来的
List<MPoint> finalPoints = rotate_poly(rectMin, radMin);
System.out.println(areaMin);
for (MPoint point : finalPoints) {
System.out.Lon() + "," + Lat());
}
return finalPoints;
}
public static void main(String[] args) throws Exception {
String trace = "112.88726,22.565811;112.88726,22.565916;112.88726,22.565998;112.887291,22.566076;112.88736,22.566124;112.887444,22.566147;11        getFinalMinRect(trace);
getFinalMinRect(trace);    }

本文发布于:2023-07-14 07:46:25,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1095759.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:弧度   王者   塑料   人物图片   出来   计算   遍历
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图