1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
| unit Unit1;
interface
uses Windows, Classes, Graphics, Forms, Buttons, Controls, ExtCtrls,
StdCtrls;
type
TForm1 = class(TForm)
Timer: TTimer;
PaintBox: TPaintBox;
Panel1: TPanel;
RadioGroup1: TRadioGroup;
rbTetraedr: TRadioButton;
rbCub: TRadioButton;
rbOktaedr: TRadioButton;
sbtRotateYZf: TSpeedButton;
sbtRotateYZt: TSpeedButton;
sbtRotateXZf: TSpeedButton;
sbtRotateXZt: TSpeedButton;
sbtRotateXYf: TSpeedButton;
sbtRotateXYt: TSpeedButton;
procedure PaintBox_onPaint(Sender: TObject);
procedure TimerTimer(Sender: TObject);
procedure sbtRotate_onMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure sbtRotate_onMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure Form_onCreate(Sender: TObject);
procedure RadioButtons_onClick(Sender: TObject);
procedure Form_onResize(Sender: TObject);
private
public
end;
var
Form1: TForm1;
RotateXYt,RotateXYf,RotateXZt,RotateXZf,RotateYZt,RotateYZf:boolean;
implementation
{$R *.DFM}
const
mCub=8;
mTetr=4;
mOkt=6;
Type
TMain = record
X, Y, Z : double;
Sd : array[1..3] of byte;
Xe, Ye : Integer;
end;
TCub = array[1..mCub] of TMain;
TOkt = array[1..mOkt] of TMain;
TTetr = array[1..mTetr] of TMain;
const
R=15;
A=r*0.8660254;
H=r*0.5;
Cub : TCub = (
{1} (X : -10; Y: -10; Z: -10; Sd:(2,4,8)),
{2} (X : -10; Y: -10; Z: 10; Sd:(0,3,7)),
{3} (X : 10; Y: -10; Z: 10; Sd:(6,4,0)),
{4} (X : 10; Y: -10; Z: -10; Sd:(5,0,0)),
{5} (X : 10; Y: 10; Z: -10; Sd:(6,8,0)),
{6} (X : 10; Y: 10; Z: 10; Sd:(7,0,0)),
{7} (X : -10; Y: 10; Z: 10; Sd:(8,0,0)),
{8} (X : -10; Y: 10; Z: -10; Sd:(0,0,0))
);
Tetr : TTetr = (
{1} (X : 0; Y: R; Z: 0; Sd:(2,3,4)),
{2} (X : 0; Y: -H; Z: R; Sd:(3,4,0)),
{3} (X : A; Y: -H; Z: -H; Sd:(4,0,0)),
{4} (X : -A; Y: -H; Z: -H; Sd:(0,0,0))
);
Okt : TOkt = (
{1} (X : -R; Y: 0; Z: 0; Sd:(6,2,4)),
{2} (X : 0; Y: 0; Z: -R; Sd:(6,3,5)),
{3} (X : R; Y: 0; Z: 0; Sd:(6,4,5)),
{4} (X : 0; Y: 0; Z: R; Sd:(6,5,0)),
{5} (X : 0; Y: -R; Z: 0; Sd:(1,0,0)),
{6} (X : 0; Y: R; Z: 0; Sd:(0,0,0))
);
Var
dxy,dxz,dyz : double; // Угол поворота по осям
Fok : integer = 800; // Фокусное расстояние
//---------------------------------------------------------------------
procedure XYZ(X,Y,Z : double; Var X2,Y2 : integer);
begin
X2:=Round(X*Fok/100+(Form1.PaintBox.Width div 2));
Y2:=Round(Y*Fok/100+(Form1.PaintBox.Height div 2));
end;
//---------------------------------------------------------------------
procedure Pw(var X,Y : double; Al : double);
var
X2, Y2 : double;
sina, cosa : double;
begin
if Al=0 then Exit;
sina :=sin(Al); cosa:=cos(Al);
X2:=(X*Cosa-Y*Sina);
Y2:=(X*Sina+Y*Cosa);
X:=X2; Y:=Y2;
end;
//---------------------------------------------------------------------
procedure TForm1.PaintBox_onPaint(Sender: TObject);
var i,j,c : integer;
qCub:TCub;
qOkt:TOkt;
qTetr:TTetr;
begin
//--------------------------------------------------
if rbCub.Checked then Begin
qCub:=Cub;
for i:=1 to mCub do begin
Pw(qCub[i].X, qCub[i].Y, dxy);
Pw(qCub[i].X, qCub[i].Z, dxz);
Pw(qCub[i].Y, qCub[i].Z, dyz);
XYZ(qCub[i].X, qCub[i].Y, qCub[i].Z, qCub[i].Xe, qCub[i].Ye);
end;
for i:=1 to mCub do
for j:=1 to 3 do
if qCub[i].Sd[J]<>0 then begin
c:=qCub[i].Sd[j];
with PaintBox.Canvas do begin
MoveTo(qCub[i].Xe, qCub[i].Ye);
LineTo(qCub[c].Xe, qCub[c].Ye);
end;
end;
end;
//---------------------------------------
if rbTetraedr.Checked then Begin
qTetr:=Tetr;
for i:=1 to mTetr do begin
Pw(qTetr[i].X, qTetr[i].Y, dxy);
Pw(qTetr[i].X, qTetr[i].Z, dxz);
Pw(qTetr[i].Y, qTetr[i].Z, dyz);
XYZ(qTetr[i].X, qTetr[i].Y, qTetr[i].Z, qTetr[i].Xe, qTetr[i].Ye);
end;
for i:=1 to mTetr do
for j:=1 to 3 do
if qTetr[i].Sd[J]<>0 then begin
c:=qTetr[i].Sd[j];
with PaintBox.Canvas do begin
MoveTo(qTetr[i].Xe, qTetr[i].Ye);
LineTo(qTetr[c].Xe, qTetr[c].Ye);
end;
end;
end;
//--------------------------------------
if rbOktaedr.Checked then Begin
qOkt:=Okt;
for i:=1 to mOkt do begin
Pw(qOkt[i].X, qOkt[i].Y, dxy);
Pw(qOkt[i].X, qOkt[i].Z, dxz);
Pw(qOkt[i].Y, qOkt[i].Z, dyz);
XYZ(qOkt[i].X, qOkt[i].Y, qOkt[i].Z, qOkt[i].Xe, qOkt[i].Ye);
end;
for i:=1 to mOkt do
for j:=1 to 3 do
if qOkt[i].Sd[J]<>0 then begin
c:=qOkt[i].Sd[j];
with PaintBox.Canvas do begin
MoveTo(qOkt[i].Xe, qOkt[i].Ye);
LineTo(qOkt[c].Xe, qOkt[c].Ye);
end;
end;
end;
//----------------------------------------
end;
//---------------------------------------------------------------------
procedure TForm1.TimerTimer(Sender: TObject);
const N:real=0.03;
begin
if RotateXYt then dxy:=dxy+N;
if RotateXZt then dxz:=dxz+N;
if RotateYZt then dyz:=dyz+N;
if RotateXYf then dxy:=dxy-N;
if RotateXZf then dxz:=dxz-N;
if RotateYZf then dyz:=dyz-N;
if (RotateXYt or RotateXYf or RotateXZt or RotateXZf or RotateYZt or RotateYZf) then PaintBox.Repaint;
end;
//---------------------------------------------------------------------
procedure TForm1.sbtRotate_onMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Sender=sbtRotateXYt then RotateXYt:=true;
if Sender=sbtRotateXYf then RotateXYf:=true;
if Sender=sbtRotateXZt then RotateXZt:=true;
if Sender=sbtRotateXZf then RotateXZf:=true;
if Sender=sbtRotateYZt then RotateYZt:=true;
if Sender=sbtRotateYZf then RotateYZf:=true;
end;
//---------------------------------------------------------------------
procedure TForm1.sbtRotate_onMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Sender=sbtRotateXYt then RotateXYt:=false;
if Sender=sbtRotateXYf then RotateXYf:=false;
if Sender=sbtRotateXZt then RotateXZt:=false;
if Sender=sbtRotateXZf then RotateXZf:=false;
if Sender=sbtRotateYZt then RotateYZt:=false;
if Sender=sbtRotateYZf then RotateYZf:=false;
end;
//---------------------------------------------------------------------
procedure TForm1.Form_onCreate(Sender: TObject);
begin
dxy:=0.3; dyz:=0.3; dxz:=0.3;
RotateXYt:=false;
RotateXYf:=false;
RotateXZt:=false;
RotateXZf:=false;
RotateYZt:=false;
RotateYZf:=false;
end;
//---------------------------------------------------------------------
procedure TForm1.RadioButtons_onClick(Sender: TObject);
begin
PaintBox.Repaint;
end;
//---------------------------------------------------------------------
procedure TForm1.Form_onResize(Sender: TObject);
begin
Fok:=Round((Width+Height)*0.8);
end;
//---------------------------------------------------------------------
end. |