我现在再用applet做图形化,遇到了个问题,如下:
我知道一些顶点坐标(x,y)
例如 x={10,20,30...} y={20,40,60...} 每一个X的数组于Y数组的位置是对应得 ,例顶点是{10,20} ,{20,40}.. 构成了不规则图形,
问题:
我如何判断我鼠标的点(x,y),在我的不规则图形的范围内呢
------解决方案--------------------
- Java code
x={10,20,30...} y={20,40,60...} Polygon p = new Polygon(x, y, x.length); //创建多边形if (p.contains(new Point(mouse.x, mouse.y))) { //判断多边形是否包含某个点 System.out.println("contains");}
------解决方案--------------------
- Java code
int[] x = new int[] { 10, 10, 30, 40 }; int[] y = new int[] { 10, 30, 60, 10 }; Polygon polygon = new Polygon(x, y, x.length); Point p = new Point(20, 25); System.out.println(polygon.contains(p)); Point q = new Point(100, 100); System.out.println(polygon.contains(q));