Title: Determine if two 3D segments are parallel to each other
Function SegmentsParallel(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4:Double):Boolean;
Var Dx1,Dx2 : Double;
Dy1,Dy2 : Double;
Dz1,Dz2 : Double;
Begin
{
Theory:
If the gradients in the following planes x-y, y-z, z-x are equal then it can be
said that the segments are parallel in 3D, However as of yet I haven't been able
to prove this "mathematically".
Worst case scenario: 6 floating point divisions and 9 floating point subtractions
}
Result := False;
{
There is a division-by-zero problem that needs attention.
My initial solution to the problem is to check divisor of the divisions.
}
Dx1 := x1-x2;
Dx2 := x3-x4;
//If (IsEqual(dx1,0.0) Or IsEqual(dx2,0.0)) And NotEqual(dx1,dx2) Then Exit;
Dy1 := y1-y2;
Dy2 := y3-y4;
//If (IsEqual(dy1,0.0) Or IsEqual(dy2,0.0)) And NotEqual(dy1,dy2) Then Exit;
Dz1 := z1-z2;
Dz2 := z3-z4;
//If (IsEqual(dy1,0.0) Or IsEqual(dy2,0.0)) And NotEqual(dy1,dy2) Then Exit;
If NotEqual(Dy1/Dx1,Dy2/Dx2) Then Exit;
If NotEqual(Dz1/Dy1,Dz2/Dy2) Then Exit;
If NotEqual(Dx1/Dz1,Dx2/Dz2) Then Exit;
Result := True;
End;
(* End Of SegmentsParallel*)
Const Epsilon = 1.0E-12;
Function IsEqual(Val1,Val2:Double):Boolean;
Var Delta:Double;
Begin
Delta := Abs(Val1-Val2);
Result := (Delta Epsilon);
End;
(* End Of Not Equal *)