3D lines intersection algorithm

杀马特。学长 韩版系。学妹 提交于 2020-01-11 10:22:08

问题


I have line direction using x,y,z

and two points A, B , I used line segment using B- A

how to get the intersection point between them

Best regards


回答1:


Sytem of equations:

The parametrice equation of a line with direction (a,b,c) and one point X(x1,x2,x3) is :

D1:(x, y, z) = (x1, y1, z1) + t1(a, b, c)

The parametrice equation of a line with 2 points A and B is :

 D2:(x, y, z) = (xa, ya, za) + t2(xb-xa, yb-ya, zb-za)

you just need to equalize D1 and D2 to get the result finding the parameter t1 and t2 that will work. (3 equations with 2 unknown)

If there is no solution there is no intersection.

Intersection with the segment only:

Now let M be you result you just need to verify :

t2 in [0,1] 

 or  0<AM.AB<||AB||^2 (M is in the segment AB)

remark:

If the representation of your line are from cartesian equations (intersection of plans) than the problem is the same but with 4 equations an 3 unknown

Example:

A (1,1,1)
B (0,0,0)
D2:(x,y,z)=(1-t2,1-t2,1-t2)

(a,b,c)=(1.-1.1)
(x1,y1,z1)=(1,0,1)
D1:(x,y,z)=(t1+1,-t1,1+t1)

(D1 and D2 are 2 diagonals of the cube of side =1 placed on 0,0,0)

let M(x,y,z) be the intersection D1, D2

we find t1 and t2 that equalize the above equation: D1 and D2

we get easily t1=-1/2 and t2=1/2

moreover t2 is in [0,1] so the resulting intersection is in [A,B]

M(1/2,1/2,1/2) =D1(t1)=D2(t2) is the solution



来源:https://stackoverflow.com/questions/7010383/3d-lines-intersection-algorithm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!