检查选定区域中的坐标 [英] Check if coordinate in selected area

查看:127
本文介绍了检查选定区域中的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个区域坐标: x1,y1 ...等等。还有一个位置 x0,y0

如何检查我的坐标是否在选定区域?

解决方案

我会向您解释如何检查(x0,y0)通过(x1,y1)和(x2,y2)的直线下方。本质上,你需要矢量(x0-x1,y0-y1)指向(x2-x1,y2-y1)的右边。这相当于说矩阵

  x0-x1 y0-y1 $​​ b 
$ b x2-x1 y2 -y1 $​​ b $ b

有一个负的行列式。所以你的条件变成:

 (x0-x1)(y2-y1)< (Y0-Y1)(X2-X1)。 

你可以得到这个区域边界的任何一条线。


I have 4 coordinates of area: x1,y1 ... etc. And have one more position x0,y0.

How to check if my coordinate in selected area?

解决方案

I will explain you how to check that (x0,y0) lies "below" the line through (x1,y1) and (x2,y2). Essentially, you want that the vector (x0-x1,y0-y1) points "to the right" of (x2-x1, y2-y1). This is equivalent to saying that the matrix

x0-x1      y0-y1

x2-x1      y2-y1

has a negative determinant. So your condition becomes

(x0-x1)(y2-y1) < (y0-y1)(x2-x1).

You get such a condition for any line bounding the area.

这篇关于检查选定区域中的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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