...Determine if two 3D segments are parallel?
Author: Arash Partow
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 Is Equal *)
function NotEqual(Val1, Val2: Double): Boolean;
var
Delta: Double;
begin
Delta := Abs(Val1 - Val2);
Result := (Delta > Epsilon);
end;
(* End Of Not Equal *)
// vérifie si 2 droites tridimensionnelles sont parallèles
printed from
www.swissdelphicenter.ch
developers knowledge base