was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

23 Visitors Online


 
...den Schneidepunkt der durch einen Punkt laufende Senkrechte zur einer Gerade bekommen?
Autor: Arash Partow
Homepage: http://www.partow.net
[ Tip ausdrucken ]  

Tip Bewertung (13):  
     


{---------------------------------------------------------------------
Two routines are made available, the first takes into account a segment
and will produce point on the given segment that is of least distance
to an external point.

The second routine is similar to the first other than the fact that it
will extended the given segment into a ray and hence also produce a point
on the ray which will produce a segment of least distance between that
point and an external point, the segment produced between the point on
the ray and the external point is guaranteed to be perpendicular to the
ray in all cases except for the instance where the external point is
collinear to ray.

Both routines come from the computational geometry library
FastGEO (url: http://fastgeo.partow.net)
---------------------------------------------------------------------}

procedure PerpendicularPntToSegment(const x1, y1, x2, y2, Px, Py: Double;
  out Nx, Ny: Double);
var
  
Ratio: Double;
  Dx: Double;
  Dy: Double;
begin
  
Dx    := x2 - x1;
  Dy    := y2 - y1;
  Ratio := ((Px - x1) * Dx + (Py - y1) * Dy) / (Dx * Dx + Dy * Dy);
  if Ratio < 0 then
  begin
    
Nx := x1;
    Ny := y1;
  end
  else if 
Ratio > 1 then
  begin
    
Nx := x2;
    Ny := y2;
  end
  else
  begin
    
Nx := x1 + (Ratio * Dx);
    Ny := y1 + (Ratio * Dy);
  end;
end;
(* End PerpendicularPntSegment *)



procedure PerpendicularPntToLine(const Rx1, Ry1, Rx2, Ry2, Px, Py: Double;
  out Nx, Ny: Double);
var
  
Ratio: Double;
  Gr1, Gr2: Double;
  Gr3, Gr4: Double;
begin
  
(*  The ray is defined by the coordinate pairs (Rx1,Ry1) and (Rx2,Ry2) *)
  
if NotEqual(Rx1, Rx2) then
    
Gr1 := (Ry2 - Ry1) / (Rx2 - Rx1)
  else
    
Gr1 := 1e300;
  Gr3 := Ry1 - Gr1 * Rx1;
  if NotEqual(Gr1, 0) then
  begin
    
Gr2   := -1 / Gr1;
    Gr4   := Py - (Gr2 * Px);
    Ratio := (Gr4 - Gr3) / (Gr1 - Gr2);
    Nx    := Ratio;
    Ny    := (Gr2 * Ratio) + Gr4;
  end
  else
  begin
    
Nx := Px;
    Ny := Ry2;
  end;
end;
(* End PerpendicularPntToLine *)


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


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