whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

27 Visitors Online


 
...Determine if two 3D segments are parallel?
Autor: Arash Partow
Homepage: http://www.partow.net
[ Print tip ]  

Tip Rating (5):  
     


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


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners