MathgeomGLS
522 строки · 15.8 Кб
1unit fEvaluate;
2
3interface
4
5uses
6Winapi.Windows,
7Winapi.Messages,
8System.SysUtils,
9System.Variants,
10System.Classes,
11System.Math,
12System.IniFiles,
13Vcl.Graphics,
14Vcl.Controls,
15Vcl.Forms,
16Vcl.Dialogs,
17Vcl.StdCtrls,
18Vcl.Buttons,
19Vcl.Menus,
20Vcl.ComCtrls,
21
22GLS.OpenGLTokens,
23GLS.Coordinates,
24GLS.VectorTypes,
25GLS.VectorGeometry,
26fDerivativeOptions,
27
28uGlobal,
29uParser;
30
31type
32TEvaluateForm = class(TForm)
33GroupBox1: TGroupBox;
34Labe1: TLabel;
35Label2: TLabel;
36Label3: TLabel;
37Label4: TLabel;
38Label5: TLabel;
39Label6: TLabel;
40EditX: TEdit;
41EditY: TEdit;
42EditZ: TEdit;
43Editdzdx: TEdit;
44Editdzdy: TEdit;
45Coordinates: TCheckBox;
46BitBtn1: TBitBtn;
47ToGrids: TCheckBox;
48EditCoordWidth: TEdit;
49ColorButton: TSpeedButton;
50ColorDialog: TColorDialog;
51dzdx_dzdy: TCheckBox;
52PopupMenu1: TPopupMenu;
53Slope1: TMenuItem;
54Degree1: TMenuItem;
55Radian1: TMenuItem;
56Label1: TLabel;
57EditArrow: TEdit;
58procedure FloatKeyPress(Sender: TObject; var Key: Char);
59procedure BitBtn1Click(Sender: TObject);
60procedure ColorButtonClick(Sender: TObject);
61procedure IntPress(Sender: TObject; var Key: Char);
62procedure EditXKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
63procedure EditYKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
64procedure EditCoordWidthKeyUp(Sender: TObject; var Key: Word;
65Shift: TShiftState);
66procedure CoordinatesClick(Sender: TObject);
67procedure ToGridsClick(Sender: TObject);
68procedure dzdx_dzdyClick(Sender: TObject);
69procedure MenuClick(Sender: TObject);
70procedure EditArrowKeyPress(Sender: TObject; var Key: Char);
71procedure EditArrowKeyUp(Sender: TObject; var Key: Word;
72Shift: TShiftState);
73private
74zValue: TGLFloat;
75dzdx, dzdy: TGLFloat;
76CurrentTag: integer;
77procedure ShowCoords(const x, y, z: TGLFloat; const c, t: Boolean);
78public
79procedure UpdateEvaluate;
80procedure UpdateCoords;
81procedure DoEvaluate;
82end;
83
84var
85EvaluateForm: TEvaluateForm;
86
87//=======================================================================
88implementation
89//=======================================================================
90
91uses
92fPlot3D;
93
94{$R *.dfm}
95
96procedure TEvaluateForm.FloatKeyPress(Sender: TObject; var Key: Char);
97begin
98with Sender as TEdit do
99if not CharInSet(Key, AnyFloat) then Key := #0;
100end;
101
102procedure TEvaluateForm.EditXKeyUp(Sender: TObject; var Key: Word;
103Shift: TShiftState);
104var
105v: TGLFloat;
106
107begin
108try
109v := StrToFloat(EditX.Text);
110except
111v := 0.0;
112end;
113ViewData.xEvaluate := v;
114DoEvaluate;
115with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
116CoordChecked, ToGridsChecked);
117Altered := True;
118end;
119
120procedure TEvaluateForm.EditYKeyUp(Sender: TObject; var Key: Word;
121Shift: TShiftState);
122var
123v: TGLFloat;
124
125begin
126try
127v := StrToFloat(EditY.Text);
128except
129v := 0.0;
130end;
131ViewData.yEvaluate := v;
132DoEvaluate;
133with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
134CoordChecked, ToGridsChecked);
135Altered := True;
136end;
137
138procedure TEvaluateForm.DoEvaluate;
139var
140e: byte;
141x0, y0, x1, y1, z1, x2, y2, z2, dx, dy, dz, Sz: extended;
142VectorPos, VectorXDir, VectorYDir: TGLVector;
143
144begin
145if Visible then
146begin
147with PlotData do //x1,y2---------------x2,y2
148begin // | |
149x0 := ViewData.xEvaluate; // | |
150y0 := ViewData.yEvaluate; // | zValue |
151dx := xInc; // | . |
152dy := yInc; // | x0,y0 |
153x1 := x0 - dx; // | |
154y1 := y0 - dy; // | |
155x2 := x0 + dx; // | |
156y2 := y0 + dy; //x1,y1---------------x2,y1
157end;
158
159zValue := ParseEvaluateFxy(x0, y0, PlotData.fxyStr, e);{ evaluate z, x0,y0 }
160EditZ.Text := FloatTostr(zValue);
161VectorPos := VectorMake(x0, y0, zValue*ViewData.xyGrid.zScale);
162
163z1 := ParseEvaluateFxy(x1, y0, PlotData.fxyStr, e); { evaluate z1, x1,y0 }
164z2 := ParseEvaluateFxy(x2, y0, PlotData.fxyStr, e); { evaluate z2, x2,y0 }
165dz := z2 - z1;
166dzdx := dz/(x2 - x1); { dzdx = slope wrt x axis }
167
168VectorXDir := VectorMake(x2 - x1, 0, dz*ViewData.xyGrid.zScale);
169case CurrentTag of
1700:Editdzdx.Text := FloatToStrF(dzdx, ffNumber, 12, 8);
1711:Editdzdx.Text := FloatToStrF(RadianToDeg(ArcTan(dzdx)), ffNumber, 12, 8)+'�';
1722:Editdzdx.Text := FloatToStrF(ArcTan(dzdx), ffNumber, 12, 8)+' Rad.';
173end;
174
175z1 := ParseEvaluateFxy(x0, y1, PlotData.fxyStr, e); { evaluate z1, x0,y1 }
176z2 := ParseEvaluateFxy(x0, y2, PlotData.fxyStr, e); { evaluate z2, x0,y2 }
177dz := z2 - z1;
178dzdy := dz/(y2 - y1); { dzdy = slope wrt y axis }
179
180VectorYDir := VectorMake(0, y2 - y1, dz*ViewData.xyGrid.zScale);
181case CurrentTag of
1820:Editdzdy.Text := FloatToStrF(dzdy, ffNumber, 12, 8);
1831:Editdzdy.Text := FloatToStrF(RadianToDeg(ArcTan(dzdy)), ffNumber, 12, 8)+'�';
1842:Editdzdy.Text := FloatToStrF(ArcTan(dzdy), ffNumber, 12, 8)+' Rad.';
185end;
186
187if dzdx_dzdy.Checked then
188begin
189with ViewData.xyGrid do if xRange.Step < yRange.Step
190then Sz := xRange.Step else Sz := yRange.Step;
191with ViewForm.xArrow do
192begin
193Scale.AsVector := VectorMake(ViewData.ArrowSize*Sz/2,
194ViewData.ArrowSize*Sz/2, ViewData.ArrowSize*Sz);
195Material.FrontProperties.Diffuse.AsWinColor := ViewData.xTextColor;
196Direction.AsVector := VectorXDir;
197Position.AsVector := VectorPos;
198end;
199
200with ViewForm.yArrow do
201begin
202Scale.AsVector := VectorMake(ViewData.ArrowSize*Sz/2,
203ViewData.ArrowSize*Sz/2, ViewData.ArrowSize*Sz);
204Material.FrontProperties.Diffuse.AsWinColor := ViewData.yTextColor;
205Direction.AsVector := VectorYDir;
206Position.AsVector := VectorPos;
207end;
208end;
209end;
210end;
211
212procedure TEvaluateForm.dzdx_dzdyClick(Sender: TObject);
213begin
214ViewData.dzdx_dyChecked := dzdx_dzdy.Checked;
215ViewForm.xArrow.Visible := dzdx_dzdy.Checked;
216ViewForm.yArrow.Visible := dzdx_dzdy.Checked;
217DoEvaluate;
218Altered := True;
219end;
220
221procedure TEvaluateForm.BitBtn1Click(Sender: TObject);
222begin
223Close;
224end;
225
226procedure TEvaluateForm.EditArrowKeyPress(Sender: TObject; var Key: Char);
227begin
228with Sender as TEdit do
229if not CharInSet(Key, PosFloat) then Key := #0;
230end;
231
232procedure TEvaluateForm.EditArrowKeyUp(Sender: TObject; var Key: Word;
233Shift: TShiftState);
234var
235w: TGLFloat;
236
237begin
238try
239w := StrToFloat(EditArrow.Text);
240except
241w := 1;
242end;
243ViewData.ArrowSize := w;
244Altered := True;
245DoEvaluate;
246end;
247
248procedure TEvaluateForm.EditCoordWidthKeyUp(Sender: TObject; var Key: Word;
249Shift: TShiftState);
250var
251w: integer;
252
253begin
254try
255w := StrToInt(EditCoordWidth.Text);
256except
257w := 3;
258end;
259ViewData.CoordWidth := w;
260ViewForm.xCoordLine.LineWidth := w;
261ViewForm.yCoordLine.LineWidth := w;
262ViewForm.zCoordLine.LineWidth := w;
263Altered := True;
264end;
265
266procedure TEvaluateForm.IntPress(Sender: TObject; var Key: Char);
267begin
268with Sender as TEdit do
269if not CharInSet(Key, ['0'..'9', #8]) then Key := #0
270end;
271
272procedure TEvaluateForm.ColorButtonClick(Sender: TObject);
273begin
274if ColorDialog.Execute then
275begin
276ViewData.CoordColor := ColorDialog.Color;
277UpdateCoords;
278Altered := True;
279end;
280end;
281
282procedure TEvaluateForm.CoordinatesClick(Sender: TObject);
283begin
284ViewData.CoordChecked := Coordinates.Checked;
285DoEvaluate;
286with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
287CoordChecked, ToGridsChecked);
288if DerivativesForm.Visible and not Coordinates.Checked then
289begin
290ViewForm.AddXLine.Visible := False;
291ViewForm.AddYLine.Visible := False;
292ViewForm.AddZLine.Visible := False;
293end;
294
295Altered := True;
296end;
297
298procedure TEvaluateForm.ToGridsClick(Sender: TObject);
299begin
300ViewData.ToGridsChecked := ToGrids.Checked;
301DoEvaluate;
302with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
303CoordChecked, ToGridsChecked);
304Altered := True;
305end;
306
307procedure TEvaluateForm.ShowCoords(const x, y, z: TGLFloat; const c, t: Boolean);
308begin
309with ViewForm do
310begin
311if c then { show coords }
312begin
313with xCoordLine do
314begin
315if t then { to grids }
316begin
317Position.SetPoint(GLyzGrid.Position.x, y, z);
318Nodes[0].X := x - GLyzGrid.Position.x;
319end
320else { +- step }
321begin
322Position.SetPoint(x - GLxyGrid.XSamplingScale.Step, y, z);
323Nodes[0].X := 2*GLxyGrid.XSamplingScale.Step;
324end;
325Visible := True;
326end;
327
328with yCoordLine do
329begin
330if t then { to grids }
331begin
332Position.SetPoint(x, GLxzGrid.Position.y, z);
333Nodes[0].Y := y - GLxzGrid.Position.y;
334end
335else { +- step }
336begin
337Position.SetPoint(x, y - GLxyGrid.YSamplingScale.Step, z);
338Nodes[0].Y := 2*GLxyGrid.YSamplingScale.Step;
339end;
340Visible := True;
341end;
342
343with zCoordLine do
344begin
345if t then { to grids }
346begin
347Position.SetPoint(x, y, GLxyGrid.Position.z);
348Nodes[0].Z := z - GLxyGrid.Position.z;
349end
350else { +- step }
351begin
352Position.SetPoint(x, y, z - GLxzGrid.ZSamplingScale.Step);
353Nodes[0].Z := 2*GLxzGrid.ZSamplingScale.Step;
354end;
355Visible := True;
356end;
357
358{ only after DerivativesForm.ApplyBtnClick if AddedAs.AddedAs = AddVolume }
359if DerivativesForm.Visible then
360begin
361case AddedData.AddedAs of
362AddDerivX:
363begin
364with AddXLine do { xCoord }
365begin
366if t then { to grids }
367begin
368Position.SetPoint(GLyzGrid.Position.x, y, dzdx*ViewData.xyGrid.zScale);
369Nodes[0].AsVector := VectorMake(x - GLyzGrid.Position.x, 0, 0);
370end
371else { +- step }
372begin
373Position.SetPoint(x - GLxyGrid.XSamplingScale.Step, y, dzdx*ViewData.xyGrid.zScale);
374Nodes[0].AsVector := VectorMake(2*GLxyGrid.XSamplingScale.Step, 0, 0);
375end;
376Visible := True;
377end;
378
379with AddYLine do { yCoord }
380begin
381if t then { to grids }
382begin
383Position.SetPoint(x, GLxzGrid.Position.y, dzdx*ViewData.xyGrid.zScale);
384Nodes[0].AsVector := VectorMake(0, y - GLxzGrid.Position.y, 0);
385end
386else { +- step }
387begin
388Position.SetPoint(x, y - GLxyGrid.YSamplingScale.Step, dzdx*ViewData.xyGrid.zScale);
389Nodes[0].AsVector := VectorMake(0, 2*GLxyGrid.YSamplingScale.Step, 0);
390end;
391Visible := True;
392end;
393
394with AddZLine do { zCoord }
395begin
396if t then { to grids }
397begin
398Position.SetPoint(x, y, GLxyGrid.Position.z);
399Nodes[0].AsVector := VectorMake(0, 0, dzdx*ViewData.xyGrid.zScale - GLxyGrid.Position.z);
400end
401else { +- step }
402begin
403Position.SetPoint(x, y, dzdx*ViewData.xyGrid.zScale - GLxzGrid.ZSamplingScale.Step);
404Nodes[0].AsVector := VectorMake(0, 0, 2*GLxzGrid.ZSamplingScale.Step);
405end;
406Visible := True;
407end;
408
409end; { AddDerivX }
410
411AddDerivY:
412begin
413with AddXLine do { xCoord }
414begin
415if t then { to grids }
416begin
417Position.SetPoint(GLyzGrid.Position.x, y, dzdy*ViewData.xyGrid.zScale);
418Nodes[0].AsVector := VectorMake(x - GLyzGrid.Position.x, 0, 0);
419end
420else { +- step }
421begin
422Position.SetPoint(x - GLxyGrid.XSamplingScale.Step, y, dzdy*ViewData.xyGrid.zScale);
423Nodes[0].AsVector := VectorMake(2*GLxyGrid.XSamplingScale.Step, 0, 0);
424end;
425Visible := True;
426end;
427
428with AddYLine do { yCoord }
429begin
430if t then { to grids }
431begin
432Position.SetPoint(x, GLxzGrid.Position.y, dzdy*ViewData.xyGrid.zScale);
433Nodes[0].AsVector := VectorMake(0, y - GLxzGrid.Position.y, 0);
434end
435else { +- step }
436begin
437Position.SetPoint(x, y - GLxyGrid.YSamplingScale.Step, dzdy*ViewData.xyGrid.zScale);
438Nodes[0].AsVector := VectorMake(0, 2*GLxyGrid.YSamplingScale.Step, 0);
439end;
440Visible := True;
441end;
442
443with AddZLine do { zCoord }
444begin
445if t then { to grids }
446begin
447Position.SetPoint(x, y, GLxyGrid.Position.z);
448Nodes[0].AsVector := VectorMake(0, 0, dzdy*ViewData.xyGrid.zScale - GLxyGrid.Position.z);
449end
450else { +- step }
451begin
452Position.SetPoint(x, y, dzdy*ViewData.xyGrid.zScale - GLxzGrid.ZSamplingScale.Step);
453Nodes[0].AsVector := VectorMake(0, 0, 2*GLxzGrid.ZSamplingScale.Step);
454end;
455Visible := True;
456end;
457
458end; { AddDerivY }
459
460AddVolume:
461begin
462AddXLine.Visible := False;
463AddYLine.Visible := False;
464AddZLine.Visible := False;
465end; { AddVolume }
466end; { case AddedData.AddedAs of... }
467end; { if DerivativesForm.Visible then... }
468end { if c then show coords }
469else
470begin { coordinate lines not visible }
471xCoordLine.Visible := False;
472yCoordLine.Visible := False;
473zCoordLine.Visible := False;
474end;
475end;
476
477with ViewData do
478begin
479EditArrow.Text := FloatToStr(ArrowSize);
480EditCoordWidth.Text := IntToStr(CoordWidth);
481ViewForm.xCoordLine.LineWidth := CoordWidth;
482ViewForm.yCoordLine.LineWidth := CoordWidth;
483ViewForm.zCoordLine.LineWidth := CoordWidth;
484end;
485end;
486
487procedure TEvaluateForm.MenuClick(Sender: TObject);
488begin
489if CurrentTag <> TMenuItem(Sender).Tag then
490begin
491case CurrentTag of
4920:Slope1.Checked := False;
4931:Degree1.Checked := False;
4942:Radian1.Checked := False;
495end;
496with Sender as TMenuItem do
497begin
498Checked := True;
499CurrentTag := Tag;
500end;
501DoEvaluate;
502end;
503end;
504
505procedure TEvaluateForm.UpdateEvaluate;
506begin
507DoEvaluate;
508with ViewData do ShowCoords(xEvaluate, yEvaluate, zValue*xyGrid.zScale,
509CoordChecked, ToGridsChecked);
510end;
511
512procedure TEvaluateForm.UpdateCoords;
513begin
514with ViewForm do
515begin
516with xCoordLine do LineColor.AsWinColor := ViewData.CoordColor;
517with yCoordLine do LineColor.AsWinColor := ViewData.CoordColor;
518with zCoordLine do LineColor.AsWinColor := ViewData.CoordColor;
519end;
520end;
521
522end.
523