So I have an arc described as a start point, end point and it's centre point. So I can easily determine angles, radious, middle point.
I've used the formula from this question
CodePudding user response:
I see that you have Delphi question, so you perhaps can reproduce that manual test. Left mouse button click for arc start (Red), middle for middle (Green), right for arc end (Blue).
IsCW
works for left-handed coordinates system, for right-handed one change comparison to >
uses... Math;
var
Form1: TForm1;
R: Integer = 200;
cx: Integer = 300;
cy: Integer = 300;
sx, sy, mx, my, ex, ey: Integer;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
l: Double;
begin
l := Hypot(x - cx, y - cy) 0.1;
case Button of
mbLeft: begin
sx := cx Round((x-cx)*R / l);
sy := cy Round((y-cy)*R / l);
end;
mbMiddle: begin
mx := cx Round((x-cx)*R / l);
my := cy Round((y-cy)*R / l);
end;
mbRight:
begin
ex := cx Round((x-cx)*R / l);
ey := cy Round((y-cy)*R / l);
end;
end;
Refresh;
end;
procedure TForm1.FormPaint(Sender: TObject);
function IsCW(sx, sy, mx, my, ex, ey: Integer): Boolean;
begin
Result := (ex-sx) * (my-sy) - (ey-sy) * (mx-sx) < 0;
end;
var
a, bx, by, c: Double;
s:string;
begin
Canvas.FillRect(ClientRect);
Canvas.Pen.Width := 3;
Canvas.Pen.Color := clBlack;
Canvas.Ellipse(cx - r, cy - r, cx r 1, cy r 1);
Canvas.Pen.Color := clRed;
Canvas.Ellipse(sx - 3, sy - 3, sx 4, sy 4);
Canvas.Pen.Color := clLime;
Canvas.Ellipse(mx - 3, my - 3, mx 4, my 4);
Canvas.Pen.Color := clBlue;
Canvas.Ellipse(ex - 3, ey - 3, ex 4, ey 4);
if IsCW(sx, sy, mx, my, ex, ey) then
s := 'CW'
else
s := 'CCW';
Canvas.TextOut(cx - 20, cy - 20, s);
end;