多边形矩形的算法? [英] Polygon in rectangle algorithm?

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

问题描述

我有一个算法,该算法可以找到点是否在一个给定的多边形:

I have an algorithm which can find if a point is in a given polygon:

 int CGlEngineFunctions::PointInPoly(int npts, float *xp, float *yp, float x, float y)
 {
     int i, j, c = 0;
     for (i = 0, j = npts-1; i < npts; j = i++) {
         if ((((yp[i] <= y) && (y < yp[j])) ||
             ((yp[j] <= y) && (y < yp[i]))) &&
             (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
             c = !c;
     }
     return c;
 }

鉴于此,我怎么可能让它检查其通过Ptopleft和Pbottomright defind的一个点,而不是一个矩形内?

given this, how could I make it check if its within a rectangle defind by Ptopleft and Pbottomright instead of a single point?

感谢

基本上,你知道你可以在Adobe Illustrator拖动来选择属于选择矩形内的所有对象?以及我的意思。 -

Basically you know how in Adobe Illustrator you can drag to select all objects that fall within the selection rectangle? well I mean that. –

推荐答案

你就不能找到多边形点之间的最小和最大x和y的值,并检查是否有任何值都是矩形的外尺寸?

Can't you just find the minimum and maximum x and y values among the points of the polygon and check to see if any of the values are outside the rectangle's dimensions?

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

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