c语言与java语言判断一个点在一个多边形里面
2014-04-25 19:01
309 查看
c代码:
bool pointInPolygon(int polySides,float polyX[],float polyY[],float x,float y) {
int i,j=polySides-1 ;
bool oddNodes=false ;
for (i=0;i<polySides; i++) {
if(polyY[i]<y && polyY[j]>=y
|| polyY[j]<y&& polyY[i]>=y) {
if(polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])<x) {
oddNodes=!oddNodes;}}
j=i;}
return oddNodes; }
java代码: 引自游戏引擎
/** Checks whether the given point is in the polygon.
* @param polygon The polygon vertices passed as an array
* @param point The point
* @return true if the point is in the polygon */
public static boolean isPointInPolygon (Array<Vector2> polygon, Vector2 point) {
Vector2 lastVertice = polygon.peek();
boolean oddNodes = false;
for (int i = 0; i < polygon.size; i++) {
Vector2 vertice = polygon.get(i);
if ((vertice.y < point.y && lastVertice.y >= point.y) || (lastVertice.y < point.y && vertice.y >= point.y)) {
if (vertice.x + (point.y - vertice.y) / (lastVertice.y - vertice.y) * (lastVertice.x - vertice.x) < point.x) {
oddNodes = !oddNodes;
}
}
lastVertice = vertice;
}
return oddNodes;
}
bool pointInPolygon(int polySides,float polyX[],float polyY[],float x,float y) {
int i,j=polySides-1 ;
bool oddNodes=false ;
for (i=0;i<polySides; i++) {
if(polyY[i]<y && polyY[j]>=y
|| polyY[j]<y&& polyY[i]>=y) {
if(polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])<x) {
oddNodes=!oddNodes;}}
j=i;}
return oddNodes; }
java代码: 引自游戏引擎
/** Checks whether the given point is in the polygon.
* @param polygon The polygon vertices passed as an array
* @param point The point
* @return true if the point is in the polygon */
public static boolean isPointInPolygon (Array<Vector2> polygon, Vector2 point) {
Vector2 lastVertice = polygon.peek();
boolean oddNodes = false;
for (int i = 0; i < polygon.size; i++) {
Vector2 vertice = polygon.get(i);
if ((vertice.y < point.y && lastVertice.y >= point.y) || (lastVertice.y < point.y && vertice.y >= point.y)) {
if (vertice.x + (point.y - vertice.y) / (lastVertice.y - vertice.y) * (lastVertice.x - vertice.x) < point.x) {
oddNodes = !oddNodes;
}
}
lastVertice = vertice;
}
return oddNodes;
}
相关文章推荐
- 实训JAVA语言设计——产生一个2-K之间的随机整数,判断一个数是否是素数
- Java语言判断输入的是否是一个英文字母
- java判断一个字符串对象是否在一个集合里面
- 我有一个集合,如下,请问,我想判断里面有没有"world"这个元素,如果有,我就添加一个"javaee"元素,请写代码实现。
- Java判断一个字符串里面是否含有中文字符
- C语言 java 判断一个数是不是质数
- Java 判断一个点是否在多边形区域内【转】
- Java 判断一个点是否在多边形区域内
- 判断一个点是否在多边形内(java)
- PNPoly算法代码例子,判断一个点是否在多边形里面
- 用C语言写一个数组,实现类似JAVA语言中ArrayList的功能
- java的一个string,如何判断它里面的值是全角的,还是半角的,还是全角半角混合的?
- Java 判断一个点是否在多边形区域内
- JAVA判断一个点坐标是否在一个多边形区域内和是否在一个圆形区域内
- JAVA判断一个字符串里面有没有汉字
- 实训JAVA语言设计——从键盘输入一个年份,判断是否是闰年
- Java 判断 一个点是不是在一个多边形围起来的区域内
- java实现判断一个经纬度坐标是否在一个多边形内(经自己亲测)
- 如何判断一个指定的经纬度点是否落在一个多边形区域内?
- JAVA入门.零基础学Java语言 MOOC 第二 第三 第四周 比较 判断 分支 循环 —————— 程序控制结构(顺序,分支,循环)