I can find many formulas for finding the distance between two skew lines. I want to calculate the distance between two line segments in one dimension.
This is easy to do with a bunch of IF statements. But I was wondering if their more effective mathematical formula.
eg. 1:
L1 = line segment 1, L2 = line segment 2; distance here is 0 due to intersection
eg. 2:
the distance here is L2x1 - L1x2
EDIT:
The only assumption is that the line segments are ordered, i.e. x2 always> x1.
Line segment 1 can be left, right, equal, etc. segment 2. This algorithm should solve for this.
EDIT 2:
I have to implement this in T-SQL (SQL Server 2008). I just need logic ... I can write T-SQL.
EDIT 3:
If the line segment is a line segment of another line, the distance is 0.
Line segment 2 is a segment of line segment 1, making the distance 0.
If they intersect or touch, the distance is 0.
IamIC source share