我正在按钮中间画一个假想的圆圈。
圆的半径是Height/2
if Height>Width
or Width/2
if Width>Height
。
现在我必须计算这个圆圈中有哪些坐标(以像素为单位)。
这个想法是,如果例如鼠标光标悬停在那个圆圈上,就会发生一些事情。
计算每个坐标是多余的;只是比较distance到中心。例如:
int radius = 5; // whatever
int deltaX = originX - mouseX, deltaY = originY - mouseY;
// compare the square distance, to avoid an unnecessary square-root
if((deltaX * deltaX) + (deltaY * deltaY) <= (radius * radius)) {
// inside the circle, or on the edge
}
为了避免一些数学运算,您还可以进行快速边界框检查,即检查矩形的区域(仅加法/减法)。这可以组合使用,即
- check the bounding box
- 如果它不在边界框中,它肯定不在圆圈内
- if it is在边界框中,进行数学计算以比较平方距离
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)