Sorry -being lazy- but is there code somewhere for computing the intersection, if any, of 2 3-d lines?
Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
In case no one has code...
Not code but some formulas and videos can be found using Google "intersection of lines in 3D" https://socratic.org/questions/how-do-i-find-the-intersection-of-two-lines-in-three-dimensional-space https://math.stackexchange.com/questions/270767/find-intersection-of-two-3d-lines/271366 http://paulbourke.net/geometry/pointlineplane/calclineline.cs has some code in C. I hope that this gets you started. On 2021-02-26 7:08 a.m., kitwallace
wrote:
Sorry -being lazy- but is there code somewhere for computing the intersection, if any, of 2 3-d lines? -- Ron Wheeler Artifact Software 438-345-3369 [hidden email] _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Thanks - I used Pauls' code - here it is in OpenSCAD in case anyone looks :
function intersection (p1,p2,p3,p4,eps=0.0001) = let (p13=p1-p3, p43=p4-p3) norm(p43) <eps ? undef : let (p21=p2-p1) norm(p21) < eps ? undef : let ( d1343= p13*p43, d4321= p43*p21, d1321= p13*p21, d4343= p43*p43, d2121= p21*p21, denom=d2121 * d4343 - d4321 * d4321) abs(denom) < eps ? undef : let (numer=d1343 * d4321 - d1321 * d4343, mua = numer / denom, mub = (d1343 + d4321 *mua ) / d4343) [p1 + mua*p21, p3 + mub*p43]; Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Anyway, here is my version that seems to be about the same: It returns undef when the lines are nearly coincident and [] if they are parallel. When crossing, it returns two points, one in each line, whose distance is less than prec. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Thanks Ronaldo - that's a bit bit more vectory - I should use assert more - although just to note that the first two asserts are too early :)
Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Free forum by Nabble | Edit this page |