3d 世界中的线-圆相交测试?
我有一个 3D 世界,其中有几个面向天空的 2D 圆圈放在地面上。
我如何检查一条线是否会从上到下与其中一个圆圈相交?
我尝试搜索,但我得到的只是这种交叉测试: http://mathworld.wolfram.com/Circle-LineIntersection.html
但它不是我需要,这是我的意思的图片: http://imageshack.us/m/192/8343/linecircleintersect.png
i have a 3d world where i have several 2d circles laying on the ground facing to the sky.
how can i check if a line will intersect one of those circles frop top-to-down?
i tried to search but all i get is this kind of intersection test:
http://mathworld.wolfram.com/Circle-LineIntersection.html
but its not what i need, here is image what i mean:
http://imageshack.us/m/192/8343/linecircleintersect.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您处于一个坐标系中,其中地面由 z = c(其中 c 为某个常数)给出,那么您可以简单地计算 z = c 的线的 x、y 坐标。现在,对于原点 x0、y0 和半径 R 的圆,您只需检查
(x - x0)^2 + (y - y0)^2 <= R^2 是否。
如果这是真的,则直线与圆相交。
If you are in a coordinate system, where the ground is given by z = c for c some constant, then you could simply calculate the x, y coordinates of the line for z = c. Now for a circle of origin x0, y0 and radius R, you would simply check if
(x - x0)^2 + (y - y0)^2 <= R^2.
If this is true, the line intersects the circle.
在 3D 意义上,您首先关心的不是圆,而是圆所在的平面。然后就可以找到射线(线)和平面(圆盘)之间的交点。
我喜欢使用齐次坐标来表示点、面和线,希望您熟悉矢量点
·
和叉积×
。方法如下:平面(圆盘)由点向量
r=[rx,ry,rz]
和法线方向向量n=[nx,ny,nz]
定义代码>.它们一起形成一个平面W=[W1,W2]=[n,-r·n]
。线(射线)由两个点向量
r_A=[rAx,rAy,rAz]
和r_B=[rBx,rBy,rBz]
定义。它们一起形成线L=[L1,L2]=[r_B-r_A, r_A×r_B]
相交点由下式定义:
P=[P1,P2]=[L1×W1 -W2*L2, -L2·W1]
,或展开为该点的坐标由
r_P = P1/P2
找到,其中P1
具有三个元素,P2
是标量。获得坐标后,您可以通过
d=sqrt((r_p-r)·(r_p-r))
检查与圆心的距离,并检查d<=R
code> 其中R
是圆的半径。请注意标量乘法*
和点积·
之间符号的差异如果您确定圆圈位于地面上 (
r=[0, 0,0]
)并正面朝上(n=[0,0,1]
),那么您可以对上述一般情况进行大量简化。[参考:Plucker 坐标]
更新:
使用地面时(+Z 向上)作为平面(圆所在的位置),然后使用 r=[rx,ry,0] 并
n=[0,0,1]
将上面的交点简化为您可以检查到圆心的距离。
In a 3D sense you are first concerned with not with a circle but with the plane where the circle lies on. Then you can find the point of intersection between the ray (line) and the plane (disk).
I like to use homogeneous coordinates for point, planes and lines and I hope you are familiar with vector dot
·
and cross products×
. Here is the method:Plane (disk) is defined by a point vector
r=[rx,ry,rz]
and a normal direction vectorn=[nx,ny,nz]
. Together they form a planeW=[W1,W2]=[n,-r·n]
.Line (ray) is defined by two point vectors
r_A=[rAx,rAy,rAz]
andr_B=[rBx,rBy,rBz]
. Together they form the lineL=[L1,L2]=[r_B-r_A, r_A×r_B]
The intersecting Point is defined by
P=[P1,P2]=[L1×W1-W2*L2, -L2·W1]
, or expanded out asThe coordinates for the point are found by
r_P = P1/P2
whereP1
has three elements andP2
is scalar.Once you have the coordinates you check the distance with the center of the circle by
d=sqrt((r_p-r)·(r_p-r))
and checkingd<=R
whereR
is the radius of the circle. Note the difference in notation between a scalar multiplication*
and a dot product·
If you know for sure that the circles lie on the ground (
r=[0,0,0]
) and face up (n=[0,0,1]
) then you can make a lot of simplifications to the above general case.[ref: Plucker Coordinates]
Update:
When using the ground (with +Z up) as the plane (where circles lie), then use
r=[rx,ry,0]
andn=[0,0,1]
and the above intersection point simplifies toof which you can check the distance to the circle center.