Getting two different intersection points for intersection of two lines in 3D

1 view (last 30 days)
According to the link1 . If my input is like this
A1=[0 0 0];
A2=[5 5 5];
B1=[0 5 5];
B2=[5 0 0];
I will get the output same output points as points [2.5000 2.5000 2.5000]
However, if I change my input to the following.
A1 =
44.2709 -6.6805 -159.7093
A2 =
0.6680 4.4271 0
B1 =
48.4957 -8.7269 -160.0394
B2 =
0.8727 4.8496 0
I will get two different points of intersection as point1 =[1.2461 4.2798 -2.1173]
point1 =[1.4910 4.6733 -2.0778]
Does anyone know how to fix this issue?
----------------Code snapshot---------------------------------------------------------
A1=[0 0 0];
A2=[5 5 5];
B1=[0 5 5];
B2=[5 0 0];
ts = [A2(:) - A1(:),-(B2(:)-B1(:))]\(B1(:) - A1(:))
point1=A1 + (A2 - A1)*ts(1)
point1=B1 + (B2 - B1)*ts(2)

Answers (1)

Matt J
Matt J on 17 Jun 2015
Edited: Matt J on 17 Jun 2015
It means your lines do not intersect. However, the 2 solutions you're obtaining are the pair of points from line A and B of minimum possible distance from each other.
  2 Comments
Don Wei
Don Wei on 17 Jun 2015
Thank you for your reply. However, I have check if these two lines are skewed or not through link2. It turns out that it is skew check is not equal to 0. This is why I am wondering what went wrong
Matt J
Matt J on 17 Jun 2015
As the link mentions, if the "skew check" is not equal zero, it means the lines are skewed. In practice, it is impossible to have an ideal intersection of two lines anyway because of floating point precision limits. Your lines may "almost" intersect. The lines in this example are rather close together,
>> point1=A1 + (A2 - A1)*ts(1);
>> point2=B1 + (B2 - B1)*ts(2);
>> norm(point1-point2)
ans =
2.3647

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!