多边形范围点判定算法
来源:互联网 发布:淘宝手机 编辑:程序博客网 时间:2024/05/24 05:20
判断一个二维坐标点是否在一个多边形范围框内,首先给出范围框各顶点的坐标(按顺时针方向给出),分别放到两个数组中再比较大小范围从而判定点是否在多边形返回框中
code如下:
public class RangePoint {double[] x_points;double[] y_points;public RangePoint(){}public RangePoint(double[] x_points,double[] y_points) {this.x_points = x_points;this.y_points = y_points;}public boolean RangeMatch(double x, double y) {int j = x_points.length - 1;boolean odd_nodes = false;for (int i = 0; i < x_points.length; i++){ if (((y_points[i] < y && y_points[j] >= y) || (y_points[j] < y && y_points[i] >= y)) && (x_points[i] <= x || x_points[j] <= x)) { odd_nodes ^= (x_points[i] + (y - y_points[i]) / (y_points[j] - y_points[i]) * (x_points[j] - x_points[i]) < x); } j = i;} if (odd_nodes==true) { return true; } return false;}public static void main(String[] args) {double[] x_points = {0, 0, 2, 2 };double[] y_points = {0, 1.8, 2, 0 };double x = 1.9;double y = 1.8;RangePoint rp = new RangePoint(x_points,y_points); if (rp.RangeMatch(x, y)) { System.out.println("This Range include Point:" + x +","+ y); }}}
好吧,这个东西有啥用呢??
看到如下测试代码你可能会觉得有用了,这个是判断某个经纬度坐标是否在给定的范围区域内,下面是故宫顶点的经纬度(可以通过ditu.google.cn点击查看到具体经纬度的值)
public static void main(String[] args) {double[] x_points = {39.922886, 39.923264, 39.913275, 39.912929 };double[] y_points = {116.391517, 116.40199, 116.402505, 116.392034 }; double x = 39.922804; double y = 116.391581; RangePoint rp = new RangePoint(x_points,y_points); if (rp.RangeMatch(x, y)) { System.out.println("This Range include Point:" + x +","+ y); } }
1 0
- 多边形范围点判定算法
- 点在多边形内判定
- 判定一个点是否在多边形内部
- 点在多边形内算法
- POJ 2318 判定点在多边形内外(二分)
- hdu 1756 Cupid's Arrow 点在多边形内部判定
- POJ 2318 TOYS(点在多边形内判定)
- ZOJ 1081 Points Within(点在多边形内判定)
- UVA 634 Polygon(模板题:判定点在多边形内)
- HDU 1756 Cupid's Arrow(判定点在多边形内)
- HDU 1756 Cupid's Arrow(点在多边形内判定)
- POJ 2318 TOYS(点在多边形内判定 刘汝佳模板)
- ZOJ 1081 Points Within(点在多边形内判定)
- 点在多边形内算法的实现
- 点在多边形内算法的实现
- 点在多边形内算法比较
- 点在多边形内算法的实现
- 判断点与多边形位置关系算法
- Oracle Database体系结构概述
- 如何通过抓包工具fiddler获取java程序的http请求
- Chewbaсca and Number (Codeforces Round #291 (Div. 2)A)
- 如何使linux系统下的root用户不保存终端历史记录到.bash_history中
- java内存中的对象
- 多边形范围点判定算法
- NIO学习
- Java线程(二):线程同步synchronized和volatile
- 百度地图如何计算两点之间距离
- C++ STL set集合容器常见用法
- mysql的学习 之一
- zookeeper basic 01 安装 验证
- Merge Sorted Array - LeetCode
- 温故而知新