Delphi Trigonometry: Useful for PCB Scripts.
Intersection of two straight lines - Online Simulation
Simulation Source: Math open Reference
Delphi code to Get Angle
const
RADIANS=57.29577951;
// If Angle is outside of 0-360 then put it within 0-360
function FixAngle(angle:double):double;
begin
while angle>= 360.0 do
angle := angle - 360.0;
while angle < 0 do
angle := angle + 360.0;
result:=angle;
end;
// Angle going from x1,y1 to x2,y2
function GetAngleDegrees(x1,y1,x2,y2:double):double;
var
part1, part2:double;
angle:double;
begin
if (x1=x2) and (y1=y2) then
begin
result:=0.0;
exit;
end;
part1:=abs(y2-y1);
if (part1=0) then begin part1:=0.0000001; y1:=y1+0.0000001; end;
part2:=abs(x2-x1);
if (part2=0) then begin part2:=0.0000001; x1:=x1+0.0000001; end;
angle:=arctan(part1/part2)*RADIANS;
if ((x1>x2) and (y1<y2)) then angle:=180-angle;
if ((x1>x2) and (y1>y2)) then angle:=angle +180;
if ((x1<x2) and (y1>y2)) then angle:=360-angle;
angle:=FixAngle(angle);
result:=angle;
end;
'via Blog this'
No comments:
Post a Comment