如何在三角形区域检测触摸 [英] How to detect touch in triangle area

查看:62
本文介绍了如何在三角形区域检测触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的应用程序,我需要将iPhone屏幕的对角线分为4个部分,并检测触摸了哪个部分。
我非常困惑,因为我的区域是三角形而不是正方形,而且我找不到解决方案来检测碰到了哪个三角形...

For my application, i need to divide diagonally the screen of my iphone in 4 parts and detect which of the part was touched. I am very confused because my areas are triangles and not squares and I can't find a solution to detect which of the triangle was touched...

我用touchesBegan方法得到了感动的Point,在这里我被卡住了... :(如何定义三角形形状并测试是否被感测了?使用View?图层?

I get the touched Point with method touchesBegan, and there I'm stuck... :( How to define triangle shapes and test if it was touched? with View? layer?

如果有人可以帮助我,那真的很酷。

It could be really cool if someone could help me.

推荐答案

此网站显示了一些算法来检查点是否在里面

This website show some algorithms to check if a point is inside a triangle or not.

http://www.blackpawn.com/texts/pointinpoly/default.html

根据应用程序应运行的速度,您可能需要预先计算并存储一个矩阵,其中将包含所有可能的x和y坐标。

Depending on how fast your application should run, you might want to precompute and store a matrix will all possible x and y coordinates. This matrix would look something like this:

point_inside [X] [Y] [triangle]

point_inside[X][Y][triangle]

其中X和Y是屏幕上的坐标, 三角形是指向该点处三角形的指针。

Where X and Y are the coordinates in your screen and "triangle" is pointer to which triangle should be in that point.

这篇关于如何在三角形区域检测触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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