Mathematica Asked by Einav Brin on December 26, 2020
I have 2 intersecting Lines emerging from the same point and I want to fined the point of intersection.
The function RegionIntersection found the origin point but failed to find the intersection.
What am I missing?
The points of the first line
In[278]:= radial[[5]]
Out[278]= {{-0.00548926, 0.256565, 0.103662}, {-0.00531428, 0.256296,
0.104157}, {-0.00500216, 0.255807, 0.105072}, {-0.00489756,
0.255665, 0.105292}, {-0.0047833, 0.255507, 0.10554}, {-0.00437606,
0.254945, 0.106429}, {-0.00399892, 0.254423,
0.107267}, {-0.00380427, 0.254162, 0.107591}, {-0.00352772,
0.253792, 0.108051}, {-0.00314683, 0.253281,
0.108689}, {-0.00286464, 0.252903, 0.109156}, {-0.00244156,
0.252314, 0.109731}, {-0.00188609, 0.251539, 0.110478}, {-0.001698,
0.251277, 0.110732}, {-0.00154332, 0.251059,
0.110934}, {-0.000930818, 0.250156, 0.111646}, {-0.000301051,
0.249206, 0.11234}, {-0.000152977, 0.248982,
0.112503}, {-0.000103015, 0.248904, 0.112553}, {-7.58942*10^-19,
0.248744, 0.112658}, {0.00062729, 0.247733, 0.113236}, {0.00122128,
0.246723, 0.113708}, {0.00139597, 0.246426, 0.113847}, {0.00156536,
0.246124, 0.113958}, {0.00211934, 0.245082, 0.114245}, {0.00272074,
0.243861, 0.114451}, {0.00276676, 0.243768, 0.114467}, {0.00279988,
0.243695, 0.114471}, {0.0032928, 0.242528, 0.114424}, {0.00356601,
0.241792, 0.1143}, {0.00367556, 0.241454, 0.114207}, {0.00385001,
0.240779, 0.113927}, {0.00390934, 0.240549, 0.113832}, {0.0039271,
0.240456, 0.113777}, {0.00400802, 0.239801, 0.113289}, {0.00401798,
0.239526, 0.113034}, {0.00400263, 0.239164, 0.112641}, {0.00395789,
0.238733, 0.112123}, {0.00393484, 0.238587, 0.111934}, {0.00389593,
0.238408, 0.111683}, {0.00382816, 0.238052, 0.111202}, {0.00368209,
0.237532, 0.110422}, {0.00367865, 0.237517, 0.110401}, {0.00367653,
0.237508, 0.110388}, {0.00366286, 0.237472, 0.11033}, {0.00352404,
0.237062, 0.10969}, {0.00348231, 0.236983, 0.109544}, {0.00332247,
0.236606, 0.108904}, {0.00322043, 0.236485, 0.108639}, {0.00308759,
0.236176, 0.108092}, {0.00298657, 0.236017, 0.107782}, {0.0028773,
0.235665, 0.107181}, {0.00282901, 0.235545, 0.10697}, {0.00276454,
0.235131, 0.106299}, {0.00275378, 0.235065, 0.106192}, {0.00275267,
0.235041, 0.106156}, {0.00273643, 0.234589, 0.105455}, {0.0027417,
0.234305, 0.105023}, {0.00275146, 0.234126, 0.104756}, {0.0027644,
0.233897, 0.104414}, {0.00275471, 0.233691, 0.104089}, {0.00273723,
0.233542, 0.103842}, {0.00272372, 0.233289, 0.103443}, {0.00268182,
0.23298, 0.102924}, {0.00266453, 0.232915, 0.102803}, {0.00265219,
0.232878, 0.10273}, {0.00257063, 0.232574, 0.102163}, {0.00251045,
0.232384, 0.101792}, {0.00247678, 0.232249, 0.101547}, {0.00240055,
0.231971, 0.101025}, {0.00239328, 0.231935, 0.100964}, {0.00234777,
0.231706, 0.100568}, {0.00232953, 0.231625, 0.100424}, {0.00232784,
0.231612, 0.100404}, {0.00229992, 0.23129, 0.0999381}, {0.0023008,
0.231253, 0.099895}, {0.00232281, 0.230906, 0.099526}, {0.00238507,
0.230583, 0.0992946}, {0.00241087, 0.23045, 0.0991999}, {0.00241803,
0.230428, 0.0991925}, {0.00257865, 0.229896,
0.0989729}, {0.0026476, 0.229709, 0.098943}, {0.00280702, 0.229263,
0.0988495}, {0.00298446, 0.228811, 0.0988369}, {0.00307763, 0.22857,
0.0988227}, {0.00331601, 0.227985, 0.0988704}, {0.00337344,
0.227843, 0.0988809}, {0.00339701, 0.227788, 0.0988911}, {0.0036847,
0.227109, 0.0990068}, {0.0038557, 0.22672, 0.0991137}, {0.00401063,
0.226367, 0.0992059}, {0.00434504, 0.225627,
0.0994693}, {0.00434531, 0.225627, 0.0994695}, {0.00434586,
0.225626, 0.0994701}, {0.00469247, 0.224861,
0.0997639}, {0.00484539, 0.224535, 0.0999086}, {0.00505669,
0.224084, 0.100107}, {0.00536986, 0.223432, 0.100423}, {0.00542857,
0.22331, 0.100483}, {0.00543126, 0.223304, 0.100486}}
The points of the second line
In[277]:= radial[[6]]
Out[277]= {{-0.00548926, 0.256565, 0.103662}, {-0.00550375, 0.256171,
0.103968}, {-0.00552739, 0.255695, 0.104345}, {-0.00554915,
0.255279, 0.104675}, {-0.00557676, 0.254884,
0.104996}, {-0.00561501, 0.254351, 0.105431}, {-0.00564671, 0.25398,
0.105738}, {-0.00569849, 0.25339, 0.106229}, {-0.00573293,
0.253042, 0.106523}, {-0.00579615, 0.252401,
0.107064}, {-0.00583288, 0.252068, 0.107348}, {-0.00590459,
0.251385, 0.107929}, {-0.00594372, 0.251062,
0.108209}, {-0.00602056, 0.250348, 0.108818}, {-0.00605372,
0.250022, 0.109094}, {-0.00611453, 0.249284,
0.109703}, {-0.00613299, 0.248951, 0.109967}, {-0.00615757,
0.248184, 0.110557}, {-0.00615286, 0.247848,
0.110799}, {-0.00612126, 0.247041, 0.111355}, {-0.00608753,
0.246715, 0.111556}, {-0.0059751, 0.245844, 0.112068}, {-0.00592312,
0.245561, 0.112217}, {-0.00573005, 0.244636,
0.112676}, {-0.00567149, 0.244412, 0.112773}, {-0.00539998,
0.243463, 0.11316}, {-0.00534348, 0.243301, 0.113214}, {-0.00499909,
0.242371, 0.113505}, {-0.0049472, 0.242259,
0.113528}, {-0.00454229, 0.241411, 0.113694}, {-0.00449047,
0.241324, 0.113701}, {-0.00402545, 0.240551,
0.113758}, {-0.00399552, 0.24051, 0.113756}, {-0.00381107, 0.240258,
0.113746}, {-0.00347784, 0.239819, 0.113717}, {-0.00342229,
0.239745, 0.113713}, {-0.0029642, 0.239224, 0.113614}, {-0.0027097,
0.238925, 0.113566}, {-0.00248733, 0.238695,
0.113505}, {-0.00224024, 0.238426, 0.113445}, {-0.00202467,
0.238218, 0.113376}, {-0.00183125, 0.238026,
0.113318}, {-0.00157016, 0.237791, 0.113224}, {-0.00138675,
0.237619, 0.113161}, {-0.00112393, 0.237407,
0.113049}, {-0.000767899, 0.237114, 0.1129}, {-0.000697285, 0.23706,
0.112868}, {-0.000658569, 0.23703, 0.11285}, {-0.000262554,
0.236769, 0.112635}, {3.1984*10^-18, 0.236594,
0.112492}, {0.000427735, 0.236355, 0.112215}, {0.000609709,
0.236259, 0.112091}, {0.000949797, 0.236113, 0.111818}, {0.00117471,
0.236019, 0.111636}, {0.00132813, 0.235969, 0.11149}, {0.00168249,
0.235862, 0.11114}, {0.00168291, 0.235862, 0.111139}, {0.00168392,
0.235862, 0.111138}, {0.00201396, 0.235808, 0.110725}, {0.00213132,
0.235794, 0.110565}, {0.00230455, 0.235797, 0.110277}, {0.00248887,
0.235821, 0.109918}, {0.00254941, 0.235832, 0.109792}, {0.00267635,
0.235883, 0.109451}, {0.00275244, 0.235908, 0.109261}, {0.00277601,
0.235923, 0.109182}, {0.00293644, 0.23601, 0.108684}, {0.00300221,
0.236089, 0.108353}, {0.00307036, 0.236147, 0.108081}, {0.00314645,
0.236309, 0.107504}, {0.00315473, 0.236319, 0.107462}, {0.00316611,
0.236355, 0.107344}, {0.00324649, 0.236497, 0.106826}, {0.00326922,
0.23657, 0.106585}, {0.00330197, 0.236695, 0.106183}, {0.00333151,
0.236899, 0.10555}, {0.00333363, 0.236904, 0.105533}, {0.00333514,
0.236908, 0.10552}, {0.00338269, 0.23711, 0.104866}, {0.00343665,
0.237307, 0.104222}, {0.00343721, 0.237317, 0.104192}, {0.00343863,
0.237326, 0.104163}, {0.00351481, 0.237519, 0.10354}, {0.00358598,
0.237692, 0.102981}, {0.00359122, 0.237718, 0.102896}, {0.0035963,
0.237747, 0.102802}, {0.00365948, 0.237909, 0.102285}, {0.00369569,
0.238031, 0.101892}, {0.00370657, 0.238097, 0.101674}, {0.00370755,
0.238187, 0.101361}, {0.0037298, 0.238277, 0.101073}, {0.00373412,
0.238334, 0.100877}, {0.00373508, 0.238454, 0.100455}, {0.0036841,
0.238606, 0.0998426}, {0.00368144, 0.238619,
0.0997937}, {0.00366991, 0.238637, 0.0997132}, {0.0036439, 0.238785,
0.0991674}, {0.0035604, 0.238852, 0.0987735}, {0.00341563,
0.238986, 0.0980316}, {0.00322836, 0.239038,
0.0974851}, {0.00307292, 0.239112, 0.096912}, {0.00288826, 0.239193,
0.0962583}, {0.00281607, 0.239241, 0.0959217}, {0.00272546,
0.239341, 0.0953017}, {0.00267671, 0.239392,
0.0949838}, {0.00267068, 0.239427, 0.0947986}, {0.00266653, 0.23957,
0.0940569}, {0.0027889, 0.239742, 0.0933001}, {0.00281127,
0.239774, 0.0931582}, {0.00299387, 0.239936,
0.0925296}, {0.00305716, 0.239992, 0.0923133}, {0.00307235,
0.240003, 0.092279}, {0.00314354, 0.240051, 0.0921227}, {0.003379,
0.240209, 0.0916068}, {0.00341864, 0.240237,
0.0915152}, {0.00360913, 0.240348, 0.0912096}}
In[271]:= Graphics3D[{Table[Line[radial[[i]]], {i, 5, 6}], Red,
Sphere[RegionIntersection[Line[radial[[5]]], Line[radial[[6]]]][[1,
1]], 0.001]}]
Out[271]=
In[272]:= Graphics3D[{Table[Line[Drop[radial[[i]], 1]], {i, 5, 6}],
Red, Sphere[
RegionIntersection[Line[Drop[radial[[5]], 1]],
Line[Drop[radial[[6]], 1]][[1, 1]]], 0.001]}]
During evaluation of In[272]:= RegionIntersection::reg: {-0.00550375,0.256171,0.103968} is not a correctly specified region.
Out[272]=
The first image show that the function RegionIntersection successfully found the first intersection, But when I delete the origin point (the first point of each line), RegionIntersection returns empty-set, thought the lines clearly intersect as can be seen in the plot.
The lines may not intersect perfectly but appear to come within about 10^-14
of each other, though numerical precision issues may be a factor. You can find this point using NMinimize
over two piecewise linear interpolations of the curves. Here pts1
and pts2
are your radial[[5]]
and radial[[6]]
respectively:
intp1 = ListInterpolation[#, InterpolationOrder -> 1] & /@ Transpose[pts1];
intp2 = ListInterpolation[#, InterpolationOrder -> 1] & /@ Transpose[pts2];
eval1[t_?NumericQ] := #[t*Length[pts1]] & /@ intp1
eval2[s_?NumericQ] := #[s*Length[pts2]] & /@ intp2
(* constrain t,s to 0.1 < t,s < 0.9 so we get the middle crossing only *)
{err, sol} = NMinimize[{SquaredEuclideanDistance[eval1[t], eval2[s]],
.1 < t < 0.9, 0.1 < s < 0.9}, {t, s}]
(* {2.26456*10^-14, {t -> 0.501307, s -> 0.595269}} *)
closest = eval1[t /. sol]
(* returns: {0.00307438, 0.236155, 0.108051} *)
Graphics3D[{Line[pts1], Line[pts2], Red, Sphere[closest, .0005]}]
Correct answer by flinty on December 26, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP