确定矩形位置的算法 [英] Algorithm to determine location in rectangle

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

问题描述

请你帮我解决这个算法问题..

我必须确定图片的哪个部分(有3个不同的部分 - 图片中的不同颜色)将是目标。

目标是由x和y坐标定义的点。



Dropbox - geogebra-export.png [ ^ ]



如果有人可以为我写if if else语句会解决这个问题,我将不胜感激。



谢谢



我有什么尝试过:



我试图根据宽度/ 3和实际x位置计算一些参数,但它不起作用。

Please, can you help me with this algorithm problem..
I have to determine in which part of picture (there are 3 different parts - different colours at picture) will be "target".
Target is point defined by x and y coordinates.

Dropbox - geogebra-export.png[^]

If someone can write for me if-else statements that will solve this problem, I would be grateful.

Thank you

What I have tried:

I tried to count some parameter based on width/3 and actual x position, but it wasn´t functional.

推荐答案

你不需要



a)a'是多边形点'例程 - winforms - C#Point in polygon - Stack Overflow [ ^ ]

b)多边形列表 - 例如

b1 )边界矩形

b2).. bn每个细分多边形



然后你测试



Dont you just need

a) a 'is point in polygon' routine - winforms - C# Point in polygon - Stack Overflow[^]
b) a list of the polygons - for example
b1) the bounding rectangle
b2)..bn each subdividing polygon

then you test

if ! point in polygon b1 // general is out of bounds check
  return error "out of bounds"

// In Bounds, so ... Find which sub polygon
for i = 0..n polygons in b2..n 
   if point in polygon[i] return polygon[i]

// Not Found
return error 


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

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