3d 世界中的线-圆相交测试?

发布于 2024-11-07 22:47:34 字数 416 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心舞飞扬 2024-11-14 22:47:34

如果您处于一个坐标系中,其中地面由 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.

与酒说心事 2024-11-14 22:47:34

在 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],或展开为

P=[ (r_B-r_A)×n-(r·n)*(r_A×r_B), -(r_A×r_B)·n ]

该点的坐标由 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] 将上面的交点简化为

r_p = [ rBy-rAy, rAx-rBx, 0] / (rAy*rBx-rAx*rBy)

您可以检查到圆心的距离。

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 vector n=[nx,ny,nz]. Together they form a plane W=[W1,W2]=[n,-r·n].

Line (ray) is defined by two point vectors r_A=[rAx,rAy,rAz] and r_B=[rBx,rBy,rBz]. Together they form the line L=[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 as

P=[ (r_B-r_A)×n-(r·n)*(r_A×r_B), -(r_A×r_B)·n ]

The coordinates for the point are found by r_P = P1/P2 where P1 has three elements and P2 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 checking d<=R where R 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] and n=[0,0,1] and the above intersection point simplifies to

r_p = [ rBy-rAy, rAx-rBx, 0] / (rAy*rBx-rAx*rBy)

of which you can check the distance to the circle center.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文