English 中文(简体)
线路——3个世界的圈子交叉试验
原标题:Line - Circle intersection test in 3d world?

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

最佳回答

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.

问题回答

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]

交叉点由<代码>P=[P1,P2]=[L1 ×W1-W2*L2,-L2-W1]界定,或扩大为[P1,P2]。

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.

如果有坐标,请通过<代码>d=sqrt(r_p-r)和核对d<=R,其中为圆环的圆顶。 缩略语:

如果你知道圈子位于地面(r=[0,0])和面上(n=[0,0,1]),那么你可以对上述一般情况作许多简化。

[参见:Plucker Coordinations

Update:

在将地面(与+Zup)作为平面(圈子)时,使用<代码>r=[rx,ry,0]和n=[0,1],上述交叉点简化

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

其中你可以检查与循环中心之间的距离。





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签