size : 1232 uploaded_on : Tue Apr 6 00:00:00 1999 modified_on : Wed Dec 8 14:03:37 1999 title : Angle between points org_filename : AngleBetweenPoints.txt author : Ulli Conrad authoremail : uconrad@gmx.net description : How to calculate the angle between two points in a coordinate system keywords : tested : not tested yet submitted_by : The CKB Crew submitted_by_email : ckb@netalive.org uploaded_by : nobody modified_by : nobody owner : nobody lang : pas file-type : text/plain category : pascal-alg-maths __END_OF_HEADER__ function AngleBetweenPoints(P1,P2 : TPoint) : real; function Distance(P1,P2 : TPoint) : real; var a,b,c : Longint; begin if P1.x>P2.x then a:=P1.x-P2.x else a:=P2.x-P1.x; if P1.y>P2.y then b:=P1.y-P2.y else b:=P2.y-P1.y; c:=(a*a)+(b*b); Distance:=sqrt(c); end; var r,c,s : real; t : real; co : real; w : real; begin { special cases } if P1.x=P2.x then begin if P2.y<P1.y then AngleBetweenPoints:=90 else AngleBetweenPoints:=270; end else if P1.y=P2.y then begin if P2.x<P1.x then AngleBetweenPoints:=180 else AngleBetweenPoints:=0; end else begin r:=Distance(P1,P2); c:=P2.x-P1.x; s:=P2.y-P1.y; co:=c/r; { Cosinus of wanted angle } t:=(sqrt(1-(co*co))/co); { Tangens of wanted angle } W:=abs((arctan(t))*(360/(2*pi)); if (P2.x>P1.x) and (P2.y<P1.y) then AngleBetweenPoints:=w; if (P1.x>P2.x) and (P2.y<P1.y) then AngleBetweenPoints:=90+(90-w); if (P1.x>P2.x) and (P1.y<P2.y) then AngleBetweenPoints:=180+w; if (P2.x>P1.x) and (P1.y<P2.y) then AngleBetweenPoints:=270+(90-w); end; end;