
21.05.2012, 20:20
|
Прохожий
|
|
Регистрация: 21.05.2012
Сообщения: 6
Репутация: 10
|
|
Вращение многоугольника вокруг заданной точки
Координаты точек обращены на угол фи подсчитывает. Проблема соединить их, выдает ошибку. Помогите, буду очень благодарен.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CheckLst, Spin;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
ListBox1: TListBox;
ListBox2: TListBox;
SpinEdit1: TSpinEdit;
Button1: TButton;
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
x1,y1,sx,sy,n:integer;
xa: array [1..100 ]of integer;
ya: array [1..100 ]of integer;
implementation
{$R *.dfm}
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if (button=mbright) then
begin
canvas.MoveTo(x,y);
x1:=x;
y1:=y;
listbox1.Items.Add(IntToStr(x));
listbox2.Items.Add(IntToStr(y));
end;
if (ssShift in Shift) then
begin
canvas.LineTo(x,y);
listbox1.Items.Add(IntToStr(x));
listbox2.Items.Add(IntToStr(y));
end;
sx:= StrToInt(listbox1.Items[0]);
sy:= StrToInt(listbox2.Items[0]);
if (((x>(sx-10))and (x<(sx+10)))and((y<(sy+10))and (y>(sy-10)))) then
begin
canvas.LineTo(sx,sy);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,a,TempX,TempY:integer;
an:real;
p: array of TPoint;
begin
a:=spinedit1.Value;
An:=(a+180)*(3.14/180);
n:=listbox1.Count;
for i:=1 to n do
begin
xa[i]:= StrToInt(listbox1.Items[i-1]);
ya[i]:= StrToInt(listbox2.Items[i-1]);
TempX:=xa[1]-xa[i];
TempY :=ya[1]-ya[i];
p[i].X:=Trunc( Cos( An) * TempX - Sin( An) * TempY );
p[i].Y:=Trunc( Sin( An) * TempX + Cos( An) * TempY );
form1.Canvas.Polygon(p);
end;
end;
end.
Админ: Пользуемся тегами для оформления кода.
|