直接上代码:
一个数据对类:PairValue
复制代码
isPointInArea 方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26/** * 数据对 * */ public class PairValue<T> { private T x; private T y; public PairValue(){ } public PairValue(T t1, T t2) { this.x = t1; this.y = t2; } public T getX() { return x; } public void setX(T x) { this.x = x; } public T getY() { return y; } public void setY(T y) { this.y = y; } }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21/*** * 判断点是否在面里 * points 一组点集合 * point 判断点 */ public static boolean isPointInArea(List<PairValue<Double>> points, PairValue<Double> point){ if(points == null || points.size() ==0 || point == null){ return false; } List<Point2D.Double> dPoints = new ArrayList<Point2D.Double>(); for(PairValue<Double> onePoint : points){ dPoints.add(new Point2D.Double(onePoint.getX(), onePoint.getY())); } GeneralPath path = getGeneralPath(dPoints); if(path == null){ return false; } Point2D.Double dPpoint = new Point2D.Double(point.getX(), point.getY()); return path.contains(dPpoint); }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14protected static GeneralPath getGeneralPath(List<Point2D.Double> points) { GeneralPath path = new GeneralPath(); if (points.size() < 3) { return null; } path.moveTo((float) points.get(0).getX(), (float) points.get(0).getY()); for (Iterator<Point2D.Double> it = points.iterator(); it.hasNext();) { Point2D.Double point = (Point2D.Double) it.next(); path.lineTo((float) point.getX(), (float) point.getY()); } path.closePath(); return path; }
最后
以上就是灵巧悟空最近收集整理的关于地图判断点是否在面里面算法的全部内容,更多相关地图判断点是否在面里面算法内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复