Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Subject 5.18: How can the distance between two lines in space be computed?

computed distance Subject
0
Posted

Subject 5.18: How can the distance between two lines in space be computed?

0

The following is robust C code from Seth Teller that computes the “points of closest approach” on two 3D lines. It also classifies the lines as parallel, intersecting, or (the generic case) skew. // computes pB ON line B closest to line A // computes pA ON line A closest to line B // return: 0 if parallel; 1 if coincident; 2 if generic (i.e., skew) int line_line_closest_points3d ( POINT *pA, POINT *pB, // computed points const POINT *a, const VECTOR *adir, // line A, point-normal form const POINT *b, const VECTOR *bdir ) // line B, point-normal form { static VECTOR Cdir, *cdir = &Cdir; static PLANE Ac, *ac = &Ac, Bc, *bc = &Bc; // connecting line is perpendicular to both vcross ( cdir, adir, bdir ); // check for near-parallel lines if ( !vnorm( cdir ) ) { *pA = *a; // all points are closest *pB = *b; return 0; // degenerate: lines parallel } // form plane containing line A, parallel to cdir plane_from_two_vectors_and_point ( ac, cdir, adir, a ); // form plane containing line B, paralle

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123