我可以使用什么算法来确定半圆内的点?
如何在具有多个“中心”的网格上执行此操作,因此具有我只想计算一次的重合点?
做到这一点最有效的方法是什么?
How can I do this on a grid with several "centers", and therefore, having coincident points that I want to count only once?
What is the most efficient way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要确定点
P
是否在半圆内,我会考虑进行两部分测试:P
是否在半径R
内>,中心的,C
?P
是否位于正确的(即占据的)半平面上?第 (1) 部分很简单:将
(P_x-C_x)^2 + (P_y-C_y)^2
(在 2d 中,当然添加 3d 中的 Z 方向)与R^ 进行比较2
(不要理会平方根,它们需要时间并且不会添加任何内容)。第 (2) 部分几乎同样简单:定义向量
b = B - C
,该向量平分指向占用半平面的半圆。然后计算向量v = P - C
并与b
进行点积。如果结果为正,则该点位于已占用的半平面内;如果为负,则该点位于未占用的半平面内;如果为 0,则该点落在分界线上。二维中的点积照常为v*b = v_x*b_x + v_y*b_y
。To find out if a point,
P
, is within a semi-circle I would consider a two part test:P
within the radius,R
, of the center,C
?P
in the correct (i.e. occupied) half plane?Part (1) is easy: compare
(P_x-C_x)^2 + (P_y-C_y)^2
(in 2d, add the Z direction in 3d, of course) withR^2
(don't bother with the square-roots, they take time and don't add anything).Part (2) is almost as easy: define the vector
b = B - C
that bisects the semi circle pointing into the occupied half plane. Then compute vectorv = P - C
and take the dot product withb
. If the result is positive the point is in the occupied half plane, if negative the point is in the unoccupied half place and if 0 the point falls on the dividing line. The dot product in 2d isv*b = v_x*b_x + v_y*b_y
as usual.