我怎么...也有多边形边缘的点 [英] How do i...have the point which are on the edge of polygon too

查看:73
本文介绍了我怎么...也有多边形边缘的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个代码可以给我一点,如果它是在多边形内部或外面;如果这个点在多边形的边缘,我需要给我更多。



我尝试了什么:



this code can give me the point if it is insde or outside the polygon ; i need to give me more if this point on the edge of thid polygon .

What I have tried:

int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
{
  int i, j, c = 0;
  for (i = 0, j = nvert-1; i < nvert; j = i++) {
    if ( ((verty[i]>testy) != (verty[j]>testy)) &&
     (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
       c = !c;
  }
  return c;
}

推荐答案

将多边形的边视为定义直线的坐标 - 每条线的等式将是简单的一阶方程x,f(x)。



每对连接的点的一个这样的等式,每个点只在一定范围内有效x范围。迭代这些等式来(1)确保x在它的范围内,并且(2)你的y值== f(x)意味着它在那个特定的行上。



方程式(x-范围,斜率,截距)可以动态设置。
Consider the sides of the polygon as coordinates defining a straight lines - the equation for each line will be a simple first order equation x, f(x).

One such equation for each pair of connected points, each only effective within a certain x range. Iterate through these equations to (1) make sure x is within it's range, and (2) your y value == f(x) means it's on that particular line.

The equations (x-range, slope, intercept) can be set up dynamically.


这篇关于我怎么...也有多边形边缘的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆