import java.io.PrintStream;
//矩形区域计算
public class RectangleAreaJudgeTest {
private float maxX = 0.0F;
private float minX = 0.0F;
private float maxY = 0.0F;
private float minY = 0.0F;
public RectangleAreaJudge(String points) {
create(points);
}
public void create(String points) {
String[] pointsArray = points.split(";");
float x1 = Float.parseFloat(pointsArray[0].split(",")[0]);
float y1 = Float.parseFloat(pointsArray[0].split(",")[1]);
float x2 = Float.parseFloat(pointsArray[2].split(",")[0]);
float y2 = Float.parseFloat(pointsArray[2].split(",")[1]);
System.out.println(x1 + "--" + y1 + "--" + x2 + "---" + y2);
if (x1 > x2) {
this.maxX = x1;
this.minX = x2;
} else {
this.maxX = x2;
this.minX = x1;
}
if (y1 > y2) {
this.maxY = y1;
this.minY = y2;
} else {
this.maxY = y2;
this.minY = y1;
}
}
public String cutDot(String s) {
int dot = s.indexOf(".");
if (dot < 0) {
return s;
}
return s.substring(0, dot) + s.substring(dot + 1, s.length());
}
public boolean isInArea(String x, String y) {
float ix = Float.parseFloat(x);
float iy = Float.parseFloat(y);
if ((ix >= this.minX) && (ix <= this.maxX) && (iy >= this.minY) && (iy <= this.maxY)) {
return true;
}
return false;
}
public boolean isInArea(double x, double y) {
if ((x >= this.minX) && (x <= this.maxX) && (y >= this.minY) && (y <= this.maxY)) {
return true;
}
return false;
}
public static void main(String[] args) {
RectangleAreaJudge area = new RectangleAreaJudge("118.126592,30.130026;119.213014,31.139031");
area = new RectangleAreaJudge("113.18389892578125,23.046248208393926;113.41529846191406,23.18013237070759");
System.out.println(area.isInArea("113.2626", "23.146577"));
}
}
地图算法(三):判断当前点是不是在该矩形上
最新推荐文章于 2023-04-19 22:36:28 发布
