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

31 Visitors Online


 
...Determine if 3 points are collinear in 3D?
Autor: Arash Partow
Homepage: http://www.partow.net
[ Print tip ]  

Tip Rating (23):  
     


function Collinear(x1, y1, z1, x2, y2, z2, x3, y3, z3: Double): Boolean;
var 
  
Dx1, Dx2: Double;
  Dy1, Dy2: Double;
  Dz1, Dz2: Double;
  Cx, Cy, Cz: Double;
  //Var AB,AC,BC:Double;
begin
  
{find the difference between the 2 points P2 and P3 to P1 }
  
Dx1 := x2 - x1;
  Dy1 := y2 - y1;
  Dz1 := z2 - z1;

  Dx2 := x3 - x1;
  Dy2 := y3 - y1;
  Dz2 := z3 - z1;

  {perform a 3d cross product}
  
Cx := Dy1 * Dz2 - Dy2 * Dz1;
  Cy := Dx2 * Dz1 - Dx1 * Dz2;
  Cz := Dx1 * Dy2 - Dx2 * Dy1;

  Result := IsEqual(Cx * Cx + Cy * Cy + Cz * Cz, 0.0);

 {
  Note:
   The method below is very stable and logical, however at the same time
   it is "VERY" inefficient, it requires 3 SQRTs which is not acceptable...
 Result:=False;
 AB:=Distance(x1,y1,z1,x2,y2,z2);
 AC:=Distance(x1,y1,z1,x3,y3,z3);
 BC:=Distance(x2,y2,z2,x3,y3,z3);

 If (AB+AC) = BC Then Result:=True
  Else
   If (AB+BC) = AC Then Result:=True
    Else
     If (AC+BC) = AB Then Result:=True;
 }
end;
(* End Of Collinear *)

// vérifier si 3 points appartiennent à une même droite tridimensionnelle
// c.a.d s'ils sont alignés.


 

Rate this tip:

poor
very good


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