判断点是否在任意多边形内(java)
1.import java.util.ArrayList;
2.
3.public class Test {
4.
5. public static void main(String[] args) {
6. double px = 113.0253;
7. double py = 23.98049;
8. ArrayListpolygonXA = new ArrayList();
9. ArrayListpolygonYA = new ArrayList();
10. polygonXA.add(113.0253);
11. polygonXA.add(113.4121);
12. polygonXA.add(113.37109);
13. polygonXA.add(113.02148);
14. // 113.18359,23.8496
15.
16. // 113.0253,23.98049 113.4121,23.9687 113.37109,2.73828
17.
18. // 113.02148,23.7539C
19.
20. polygonYA.add(23.98049);
21. polygonYA.add(23.9687);
22. polygonYA.add(23.73828);
23. polygonYA.add(23.7539);
24. Test test = new Test();
25. System.out.println(test.isPointInPolygon(px, py, polygonXA, polygonYA));
26. }
27.
28. public boolean isPointInPolygon(double px, double py,
29. ArrayListpolygonXA, ArrayListpolygonYA) {
30. boolean isInside = false;
31. double ESP = 1e-9;
32. int count = 0;
33. double linePoint1x;
34. double linePoint1y;
35. double linePoint2x = 180;
36. double linePoint2y;
37.
38. linePoint1x = px;
39. linePoint1y = py;
40. linePoint2y = py;
41.
42. for (int i = 0; i < polygonXA.size() - 1; i++) {
43. double cx1 = polygonXA.get(i);