Android Path类中有直接能判断坐标点是否在Path内的吗
答案:2 悬赏:20 手机版
解决时间 2021-01-26 00:03
- 提问者网友:杀生予夺
- 2021-01-25 20:27
Android Path类中有直接能判断坐标点是否在Path内的吗
最佳答案
- 五星知识达人网友:拜訪者
- 2021-01-25 21:25
private boolean pointInPath(Path path, Point point) {
RectF bounds = new RectF();
path.computeBounds(bounds, true);
Region region = new Region();
region.setPath(path, new Region((int) bounds.left, (int) bounds.top, (int) bounds.right, (int) bounds.bottom));
return region.contains(point.x, point.y);
}将Path 转变成多个Rect,然后从Rect里面判断是否包含某个点
RectF bounds = new RectF();
path.computeBounds(bounds, true);
Region region = new Region();
region.setPath(path, new Region((int) bounds.left, (int) bounds.top, (int) bounds.right, (int) bounds.bottom));
return region.contains(point.x, point.y);
}将Path 转变成多个Rect,然后从Rect里面判断是否包含某个点
全部回答
- 1楼网友:时间的尘埃
- 2021-01-25 22:50
下面的代码描述了一个套索类,该类可以判断一个点是否在用户手指所画的一个套索区域中: public class lasso { // polygon coordinates private float[] mpolyx, mpolyy; // number of size in polygon private int mpolysize; public lasso(float[] px, float[] py, int ps) { this.mpolyx = px; this.mpolyy = py; this.mpolysize = ps; } public lasso(list<pointf> pointfs) { this.mpolysize = pointfs.size(); this.mpolyx = new float[this.mpolysize]; this.mpolyy = new float[this.mpolysize]; for (int i = 0; i < this.mpolysize; i++) { this.mpolyx[i] = pointfs.get(i).x; this.mpolyy[i] = pointfs.get(i).y; } log.d("lasso", "lasso size:" + mpolysize); } public boolean contains(float x, float y) { boolean result = false; for (int i = 0, j = mpolysize - 1; i < mpolysize; j = i++) { if ((mpolyy[i] < y && mpolyy[j] >= y) || (mpolyy[j] < y && mpolyy[i] >= y)) { if (mpolyx[i] + (y - mpolyy[i]) / (mpolyy[j] - mpolyy[i]) * (mpolyx[j] - mpolyx[i]) < x) { result = !result; } } } return result; } } 当用户手指在屏幕上划动时,可以保存手指划过的点用来实例化lasso类,也可以在用户手指抬起后通过pathmeasure类来对封闭的path对象取点,然后实例化lasso类。 lasso类中的contains方法即是判断点是否在多边形内
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯