MathgeomGLS
191 строка · 4.2 Кб
1unit fCirclein3D;
2
3interface
4
5uses
6Winapi.Windows,
7Winapi.Messages,
8System.SysUtils,
9System.Variants,
10System.Classes,
11System.Math,
12Vcl.Graphics,
13Vcl.Controls,
14Vcl.Forms,
15Vcl.Dialogs,
16Vcl.ComCtrls,
17
18GLS.Objects,
19GLS.Scene,
20Vcl.StdCtrls,
21GLS.SceneViewer,
22GLS.Coordinates,
23GLS.BaseClasses,
24GLS.SimpleNavigation;
25
26type
27TForm1 = class(TForm)
28GLScene1: TGLScene;
29GLSceneViewer1: TGLSceneViewer;
30sbSegments: TScrollBar;
31Label1: TLabel;
32Camera: TGLCamera;
33LightSource: TGLLightSource;
34dcMeridian: TGLDummyCube;
35Meridian: TGLLines;
36Label2: TLabel;
37sbWidth: TScrollBar;
38Label3: TLabel;
39sbHeight: TScrollBar;
40Label4: TLabel;
41ScrollBar4: TScrollBar;
42chbSpline: TCheckBox;
43GLSimpleNavigation1: TGLSimpleNavigation;
44chbNodes: TCheckBox;
45chbDash: TCheckBox;
46Parallel: TGLLines;
47StatusBar1: TStatusBar;
48dcParallel: TGLDummyCube;
49dcGeogrid: TGLDummyCube;
50Merid1: TGLLines;
51Paral1: TGLLines;
52Sphere: TGLSphere;
53procedure chbSplineClick(Sender: TObject);
54procedure sbCircleChange(Sender: TObject);
55procedure FormCreate(Sender: TObject);
56procedure chbNodesClick(Sender: TObject);
57procedure chbDashClick(Sender: TObject);
58private
59public
60procedure BuildParallels;
61procedure BuildOrbit;
62end;
63
64var
65Form1: TForm1;
66
67implementation
68
69{$R *.dfm}
70{ TForm1 }
71
72// ---------------------------------------------------------------------------
73procedure TForm1.BuildParallels;
74var
75A, B: Double;
76I, Segments: Integer;
77RotationAngle, theta: Double;
78x, y, xCenter, xRotated: Double;
79yCenter, yRotated: Double;
80
81begin
82Segments := sbSegments.Position;
83A := sbWidth.Position / 100;
84B := sbHeight.Position / 100;
85RotationAngle := DegToRad(ScrollBar4.Position);
86
87Meridian.Nodes.Clear;
88
89xCenter := 0;
90yCenter := 0;
91for I := 0 to Segments do
92begin
93theta := 360 * (I / Segments) * (PI / 180);
94
95x := xCenter + A * Cos(theta);
96y := yCenter + B * Sin(theta);
97xRotated := xCenter + (x - xCenter) * Cos(RotationAngle) - (y - yCenter) *
98Sin(RotationAngle);
99yRotated := yCenter + (x - xCenter) * Sin(RotationAngle) + (y - yCenter) *
100Cos(RotationAngle);
101
102Meridian.Nodes.AddNode(xRotated, 0, yRotated);
103// Meridian.PitchAngle := 90;
104end;
105end;
106
107// ---------------------------------------------------------------------------
108procedure TForm1.BuildOrbit;
109var
110A, B: Double;
111I: Integer;
112theta: Double;
113x, y, xCenter, xRotated: Double;
114yCenter, yRotated: Double;
115
116const
117Segments = 32;
118circleWidth = 1;
119circleHeight = 1;
120RotationAngle = 0;
121
122begin
123A := circleWidth;
124B := circleHeight;
125
126Parallel.Nodes.Clear;
127
128xCenter := 0;
129yCenter := 0;
130for I := 0 to Segments do
131begin
132theta := 360 * (I / Segments) * (PI / 180);
133
134x := xCenter + A * Cos(theta);
135y := yCenter + B * Sin(theta);
136xRotated := xCenter + (x - xCenter) * Cos(RotationAngle) - (y - yCenter) *
137Sin(RotationAngle);
138yRotated := yCenter + (x - xCenter) * Sin(RotationAngle) + (y - yCenter) *
139Cos(RotationAngle);
140
141Parallel.Nodes.AddNode(xRotated, 0, yRotated);
142Parallel.PitchAngle := 90;
143end;
144end;
145
146// ---------------------------------------------------------------------------
147procedure TForm1.FormCreate(Sender: TObject);
148begin
149BuildParallels;
150BuildOrbit;
151end;
152
153// ---------------------------------------------------------------------------
154procedure TForm1.sbCircleChange(Sender: TObject);
155begin
156BuildParallels;
157end;
158
159// ---------------------------------------------------------------------------
160procedure TForm1.chbNodesClick(Sender: TObject);
161begin
162if chbNodes.Checked then
163begin
164Meridian.NodesAspect := lnaCube;
165Meridian.NodeSize := 0.05;
166end
167else
168begin
169Meridian.NodesAspect := lnaInvisible;
170Meridian.NodeSize := 0.005;
171end;
172end;
173
174// ========================================================================
175procedure TForm1.chbSplineClick(Sender: TObject);
176begin
177if chbSpline.Checked then
178Meridian.SplineMode := lsmCubicSpline
179else
180Meridian.SplineMode := lsmLines;
181end;
182
183procedure TForm1.chbDashClick(Sender: TObject);
184begin
185if chbDash.Checked then
186Meridian.SplineMode := lsmSegments
187else
188Meridian.SplineMode := lsmLines;
189end;
190
191end.
192