Edit:
Ok i figured out what was wrong.
I switched the x and y coords...
So this one works perfect.
SCAR Code:
function FindAngle(cx, cy, x, y, Radius: integer): integer;
var
i: integer;
Canvas: TCanvas;
begin
DisplayDebugImgWindow(500, 500);
Canvas:= GetDebugCanvas;
Canvas.Rectangle(0, 0, 500, 500);
Canvas.Pixels[cx, cy]:= 255;
Canvas.Pixels[x, y]:= 255;
Canvas.Pen.Color:= ClBlue;
Canvas.MoveTo(cx, cy);
Canvas.LineTo(x, y);
Result:= Round((ArcTan2(y - cy, x - cx) * (180 / Pi)) + 90);
if Result < 0 then
Result:= Result + 360;
if Result > 360 then
Result:= Result - 360;
WriteLn(inttostr(result));
for i:= 1 to 10 do
for Result := 0 to 360 do
if Abs(((Round(Sin(Result * Pi / 180) * Radius) + cx) - x)) < i then
if Abs(((Round(Cos(Result * Pi / 180) * -Radius) + cy) - y)) < i then
begin
WriteLn(inttostr(result));
Exit;
end;
Result:= -1;
WriteLn('Error finding angle.');
end;
begin
x1:= random(500);
x2:= random(500);
y1:= random(500);
y2:= random(500);
writeln(inttostr(x1));
writeln(inttostr(y1));
writeln(inttostr(x2));
writeln(inttostr(y2));
writeln('');
writeln(inttostr(Distance(x1, y1, x2, y2)));
findangle(x1, y1, x2, y2, Distance(x1, y1, x2, y2));
end.