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); }