先日、apoint(X,Y)
がポリゴン内にあるかどうかを計算するクラスを Java で作成しました。(X
とY
はdouble
、地理座標になるため)。
Java にはクラスがあることは知っていますが、andを使用Polygon
する必要がありました。Path2D
Point2D
Polygon
double
でポリゴンを作成したらPath2D
、その方法を使用してcontains
(Path2D
持っていた)、問題は解決しました。
しかし今、私は Android にインポートしたいのですが、インポートするPath2D
必要があるため、問題はここにあります:
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
Androidにはawtが存在しないため、使用できません。
Path2D
では、 hadcontains
メソッドに似たクラスはありますか? または私は自分で計算する必要がありますか?
を使用してJavaで行った方法は次のPath2D
とおりです。
private void ConstructPolygon(Vector<Point2D> coodinates)
{
this.polygon.moveTo(coodinates.get(0).getX(), coodinates.get(0).getY());
//System.out.println(coodinates.get(0).getX() + " " + coodinates.get(0).getY());
//System.out.println("asda");
for(int i = 1; i < this.num_points; i++)
{
//System.out.println(coodinates.get(i).getX() + " " + coodinates.get(i).getY());
this.polygon.lineTo(coodinates.get(i).getX(), coodinates.get(i).getY());
}
this.polygon.closePath();
}
public boolean InsideCity(Point2D punto)
{
return this.polygon.contains(punto);
}