-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSupport.pas
More file actions
749 lines (647 loc) · 19.4 KB
/
Support.pas
File metadata and controls
749 lines (647 loc) · 19.4 KB
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
unit Support;
{$MODE Delphi}
interface
uses
Types, SysUtils, Math;
const
NilPoint: TPoint =
(
X: 0;
Y: 0;
);
InfinityPoint: TPoint =
(
X: MaxInt;
Y: MaxInt;
);
PRECISION = 0.00001;
type
TPoints = array of TPoint;
TRotationMatrix = class; //forward declaration
TPrecisePoint = class
private
_x, _y: Real;
function getPoint(): TPoint;
procedure setPoint(p: TPoint);
public
function pointDistance(p: TPrecisePoint): Real; //vrati vzdialenost bodu od bodu
function toString(): AnsiString; override; //vrati textovu reprezentaciu
function clone(): TPrecisePoint; //vrati kopiu bodu
constructor Create(x, y: Real); overload; //vytvori bod zo suradnic
constructor Create(p: TPoint); overload; //vytvori bod z bodu :)
property point: TPoint read getPoint write setPoint; //vrati bod ako record
property x: Real read _x write _x; //X suradnica bodu
property y: Real read _y write _y; //Y suradnica bodu
end;
TPrecisePoints = array of TPrecisePoint;
TPlanarVector = class
private
_x, _y: Real;
public
function getLength(): Real; //vrati dlzku vektora
function getPerpendicularVector(): TPlanarVector; //vrati kolmy vektor
function toString(): AnsiString; override; //vrati textovu reprezentaciu
function clone(): TPlanarVector; //vrati kopiu vektora
procedure rotate(angle: Real); overload; //otoci vektor o zadany uhol
procedure rotate(matrix: TRotationMatrix); overload; //otoci vektor o maticu
procedure perpendicular(); //zmeny vektor na kolmy
procedure reverse(); //otoci vektor
procedure normalize(); //vytvori vektor s dlzkov 1
constructor Create(x, y: Real); overload; //vytvori priamo z suradnic
constructor Create(x1, y1, x2, y2: Integer); overload; //vytvori z danych bodov
constructor Create(a, b: TPrecisePoint); overload; //vytvori vektor z 2 presnych bodov
constructor Create(a, b: TPoint); overload; //vytvori vektor z 2 bodov (triedy)
property x: Real read _x write _x; //X suradnica vektoru
property y: Real read _y write _y; //Y suradnica vektoru
end;
TGeneralLineEquation = class //ak je vektror normalovy nulovy tak da prianku rovnobeznu z osou X
private
_v: TPlanarVector;
_p: TPrecisePoint;
function getA(): Real;
function getB(): Real;
function getC(): Real;
procedure setControlVector(v: TPlanarVector);
procedure setControlPoint(p: TPrecisePoint);
public
function pointOnLine(p: TPoint): Boolean; //vrati true ak je bod na priamke, inak false
function pointDistance(p: TPoint): Integer; //vrati vzdialenost bodu od priamky
function solve(x, y: Real): Real; overload; //dosadi do rovnice x a y a vrati hodnotu
function solve(p: TPoint): Real; overload; //to iste ako s predchadzajuce akurat s bodom
function toString(): AnsiString; override;
function clone(): TGeneralLineEquation; //vrati kopiu prianky
procedure perpendicular(p: TPrecisePoint); overload; //zmeny priamku na kolmu, prechadzajucu zadanym bodom
procedure perpendicular(p: TPoint); overload; //zmeny priamku na kolmu, prechadzajucu zadanym bodom
procedure rotate(angle: Real; p: TPrecisePoint); //otoci priamku o zadany uhol okolo bodu P, ak je nil pouzije controlPoint
constructor Create(x1, y1, x2, y2: Integer); overload; //vytvori priamku z 2 bodov (zadane cele suradnice)
constructor Create(a, b: TPoint); overload; //vytvori priamku z 2 bodov
constructor Create(a, b: TPrecisePoint); overload; //vytvori priamku z 2 bodov
constructor Create(point: TPoint; normal: TPlanarVector); overload; //vytvori priamku z bodu a normaloveho vektora
constructor Create(point: TPrecisePoint; normal: TPlanarVector); overload; //vytvori priamku z bodu a normaloveho vektora
destructor Destroy(); override;
property controlPoint: TPrecisePoint read _p write setControlPoint; //riadiaci bod
property controlVector: TPlanarVector read _v write setControlVector; //riadiaci vektor, normala
property a: Real read getA;
property b: Real read getB;
property c: Real read getC;
end;
TGeneralEllipseEquation = class
private
_m: TPrecisePoint;
_a, _b: Real;
function getF(): Real;
public
function pointInEllipse(p: TPoint): Boolean;
function pointDistance(p: TPoint): Integer; //vzdialenost bodu od elipsi
function lineIntersection(l: TGeneralLineEquation): TPrecisePoints; overload;
function lineIntersection(a, b, c: Real): TPrecisePoints; overload;
function xToPoint(x: Real): TPrecisePoint; //vrati bod ktory je na elipse a x suradnicu x - vrati bod s kladnou zlozkov y
function yToPoint(y: Real): TPrecisePoint; //vrati bod ktory je na elipse a x suradnicu y - vrati bod s kladnou zlozkov x
function toString(): AnsiString; override;
function getPoints(): TPoints;
constructor Create(x, y, a, b: Real);
destructor Destroy; override;
property a: Real read _a write _a; //semimajor axis
property b: Real read _b write _b; //semiminor axis
property f: Real read getF; //flattening
property centre: TPrecisePoint read _m write _m;
end;
TRotationMatrix = class
private
_matrix: array [0..1] of array [0..1] of Real;
public
procedure vectorMultiply(v: TPlanarVector); //vynasobi vektor maticou
constructor Create(angle: Real); //vytvori maticu otocenia
end;
TSupport = class
private
class function crossProductLength(v, u: TPlanarVector): Real;
class function dotProduct(v, u: TPlanarVector): Real;
public
class function distance(a, b: TPrecisePoint): Real; overload;
class function distance(a, b: TPoint): Real; overload;
class function angle(v, u: TPlanarVector): Real;
class function rotate(point, around: TPrecisePoint; angle: Real): TPrecisePoint; overload; //vracia prvy argument
class function rotate(point, around: TPoint; angle: Real): TPoint; overload;
class function rotate(point: TPrecisePoint; around: TPoint; angle: Real): TPrecisePoint; overload;
class function rotate(point: TPoint; around: TPrecisePoint; angle: Real): TPoint; overload;
class function binomialCoefficient(n, k: Integer): Integer;
end;
implementation
//-------------------TPrecisePoint-----------------------
function TPrecisePoint.getPoint(): TPoint;
begin
Result.X := round(_x);
Result.Y := round(_y);
end;
procedure TPrecisePoint.setPoint(p: TPoint);
begin
_x := p.X;
_y := p.Y;
end;
function TPrecisePoint.pointDistance(p: TPrecisePoint): Real;
begin
result := abs(sqrt(sqr(p.x - x) + sqr(p.y - y)));
end;
function TPrecisePoint.toString(): String;
begin
Result := 'X: ' + FloatToStrF(x, ffFixed, 2, 2) + ' Y: ' + FloatToStrF(y, ffFixed, 2, 2);
end;
function TPrecisePoint.clone(): TPrecisePoint;
begin
Result := TPrecisePoint.Create(x, y);
end;
constructor TPrecisePoint.Create(x, y: Real);
begin
_x := x;
_y := y;
end;
constructor TPrecisePoint.Create(p: TPoint);
begin
Create(p.X, p.Y);
end;
//------------------TSupport----------------------
class function TSupport.crossProductLength(v, u: TPlanarVector): Real;
begin
Result := v.x*u.y - v.y*u.x;
end;
class function TSupport.dotProduct(v, u: TPlanarVector): Real;
begin
Result := (v.x * u.x) + (v.y * u.y);
end;
class function TSupport.distance(a, b: TPrecisePoint): Real;
begin
Result := a.pointDistance(b)
end;
class function TSupport.distance(a, b: TPoint): Real;
begin
Result := sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
end;
class function TSupport.angle(v, u: TPlanarVector): Real; //moze hodit invalid floating point op - uz nemoze :)
begin
Result := 0;
if ((u.getLength * v.getLength = 0)) then
Exit;
Result := ArcSin(crossProductLength(v, u) / (u.getLength * v.getLength));
Result := (Result / Pi) * 180;
end;
class function TSupport.rotate(point, around: TPrecisePoint; angle: Real): TPrecisePoint;
var
v: TPlanarVector;
begin
v := TPlanarVector.Create(around, point);
v.rotate(angle);
point.x := around.x - v.x;
point.y := around.y - v.y;
v.Free;
Result := point;
end;
class function TSupport.rotate(point, around: TPoint; angle: Real): TPoint;
var
v: TPlanarVector;
begin
v := TPlanarVector.Create(around, point);
v.rotate(angle);
Result.x := round(around.x - v.x);
Result.y := round(around.y - v.y);
v.Free;
end;
class function TSupport.rotate(point: TPrecisePoint; around: TPoint; angle: Real): TPrecisePoint;
var
v: TPlanarVector;
pom: TPrecisePoint;
begin
pom := TPrecisePoint.Create(around);
v := TPlanarVector.Create(pom, point);
v.rotate(angle);
point.x := around.x - v.x;
point.y := around.y - v.y;
v.Free;
pom.Free;
Result := point;
end;
class function TSupport.rotate(point: TPoint; around: TPrecisePoint; angle: Real): TPoint;
var
v: TPlanarVector;
pom: TPrecisePoint;
begin
pom := TPrecisePoint.Create(point);
v := TPlanarVector.Create(around, pom);
v.rotate(angle);
Result.x := round(around.x - v.x);
Result.y := round(around.y - v.y);
v.Free;
pom.Free;
end;
class function TSupport.binomialCoefficient(n, k: Integer): Integer;
var
i: Integer;
begin
Result := 1;
if ((n < 1) or (k < 0)) then
Result := 0;
if ((n > 0) and (k > 0)) then
begin
for i := 1 to n do
Result := Result * i;
for i := 1 to k do
Result := Result div i;
for i := 1 to n - k do
Result := Result div i;
end;
end;
//----------------TPlanarVector-------------------
function TPlanarVector.getLength(): Real;
begin
Result := sqrt(_x*_x + _y*_y);
end;
function TPlanarVector.getPerpendicularVector(): TPlanarVector;
begin
Result := TPlanarVector.Create(-y, x);
end;
function TPlanarVector.toString(): String;
begin
Result := 'X: ' + FloatToStrF(x, ffFixed, 2, 2) +
' Y: ' + FloatToStrF(y, ffFixed, 2, 2) +
' length: ' + FloatToStrF(getLength, ffFixed, 2, 2);
end;
function TPlanarVector.clone(): TPlanarVector;
begin
Result := TPlanarVector.Create(x, y);
end;
procedure TPlanarVector.rotate(angle: Real);
var
matrix: TRotationMatrix;
begin
matrix := TRotationMatrix.Create(angle);
rotate(matrix);
matrix.Free();
end;
procedure TPlanarVector.rotate(matrix: TRotationMatrix);
begin
matrix.vectorMultiply(Self);
end;
procedure TPlanarVector.perpendicular();
var
pom: Real;
begin
pom := -_y;
_y := _x;
_x := pom;
end;
procedure TPlanarVector.normalize();
var
length: Real;
begin
length := getLength;
if (length = 0) then
Exit;
_x := _x / length;
_y := _y / length;
end;
procedure TPlanarVector.reverse();
begin
_x := -_x;
_y := -_y;
end;
constructor TPlanarVector.Create(x, y: Real);
begin
_x := x;
_y := y;
end;
constructor TPlanarVector.Create(x1, y1, x2, y2: Integer);
begin
Create(x1 - x2, y1 - y2);
end;
constructor TPlanarVector.Create(a, b: TPrecisePoint);
begin
Create(a.x - b.x, a.y - b.y);
end;
constructor TPlanarVector.Create(a, b: TPoint);
begin
Create(a.X - b.X, a.Y - b.Y);
end;
//--------------TGeneralLineEquation---------------
function TGeneralLineEquation.getA(): Real;
begin
Result := _v.x;
end;
function TGeneralLineEquation.getB(): Real;
begin
Result := _v.y;
end;
function TGeneralLineEquation.getC(): Real;
begin
Result := -((a * _p.x) + (b * _p.y));
end;
function TGeneralLineEquation.pointOnLine(p: TPoint): boolean;
begin
Result := (a * p.x + b * p.y + c) = 0;
end;
function TGeneralLineEquation.pointDistance(p: TPoint): Integer;
begin
if ((a = 0) and (b = 0)) then //ak to podstete ani nieje priamka, tedaboli zadane rovnake body
Result := round(TSupport.distance(p, _p.point))
else
result := abs(round((a*p.X + b*p.Y + c) / sqrt(a*a + b*b)));
end;
function TGeneralLineEquation.solve(x, y: Real): Real;
begin
Result := a*x + b*y + c;
end;
function TGeneralLineEquation.solve(p: TPoint): Real;
begin
Result := solve(p.X, p.Y);
end;
procedure TGeneralLineEquation.setControlVector(v: TPlanarVector);
begin
if (v <> nil) then
begin
if (_v <> nil) then
_v.Free;
_v := v
end
else
raise EInvalidPointer.Create('Vector can not be nil.');
end;
procedure TGeneralLineEquation.setControlPoint(p: TPrecisePoint);
begin
if (p <> nil) then
begin
if (_p <> nil) then
_p.Free;
_p := p
end
else
raise EInvalidPointer.Create('Point can not be nil.');
end;
function TGeneralLineEquation.toString(): String;
begin
Result := FloatToStrF(a, ffFixed, 2, 2) + '*x + ' +
FloatToStrF(b, ffFixed, 2, 2) + '*y + ' +
FloatToStrF(c, ffFixed, 2, 2) + ' = 0';
end;
function TGeneralLineEquation.clone(): TGeneralLineEquation;
begin
Result := TGeneralLineEquation.Create(controlPoint.clone(), controlVector.clone());
end;
procedure TGeneralLineEquation.perpendicular(p: TPoint);
begin
controlVector.perpendicular();
if (_p <> nil) then
_p.Free;
_p := TPrecisePoint.Create(p);
end;
procedure TGeneralLineEquation.perpendicular(p: TPrecisePoint);
begin
controlVector.perpendicular();
if (_p <> nil) then
_p.Free;
_p := p.clone();
end;
procedure TGeneralLineEquation.rotate(angle: Real; p: TPrecisePoint);
var
pom: TPlanarVector;
begin
_v.rotate(angle);
pom := TPlanarVector.Create(p, _p);
pom.rotate(angle);
_p.x := p.x - pom.x;
_p.y := p.y - pom.y;
pom.Free;
end;
constructor TGeneralLineEquation.Create(x1, y1, x2, y2: Integer);
begin
if ((x1 = x2) and (y1 = y2)) then
x2 := x2 + 10;
_p := TPrecisePoint.Create(x1, y1);
_v := TPlanarVector.Create(x1, y1, x2, y2);
_v.perpendicular();
_v.normalize();
end;
constructor TGeneralLineEquation.Create(a, b: TPoint);
begin
Create(a.X, a.Y, b.X, b.Y);
end;
constructor TGeneralLineEquation.Create(point: TPoint; normal: TPlanarVector);
begin
if (normal = nil) then
raise EInvalidPointer.Create('Vector can not be nil.');
_p := TPrecisePoint.Create(point);
_v := normal.clone();
if (_v.getLength = 0) then
_v.x := _v.x + 10;
_v.normalize();
end;
constructor TGeneralLineEquation.Create(point: TPrecisePoint; normal: TPlanarVector);
begin
if (normal = nil) then
raise EInvalidPointer.Create('Vector can not be nil.');
if (point = nil) then
raise EInvalidPointer.Create('Point can not be nil.');
_p := point.clone();
_v := normal.clone();
if (_v.getLength = 0) then
_v.x := _v.x + 10;
_v.normalize();
end;
constructor TGeneralLineEquation.Create(a, b: TPrecisePoint);
begin
if ((a = nil) or (b = nil)) then
raise EInvalidPointer.Create('Point can not be nil.');
_p := a.clone();
_v := TPlanarVector.Create(a, b);
_v.perpendicular();
_v.normalize();
end;
destructor TGeneralLineEquation.Destroy();
begin
_v.Free();
_p.Free();
end;
//-------------------TRotationMatrix---------------
procedure TRotationMatrix.vectorMultiply(v: TPlanarVector);
var
x, y: Real;
begin
x := v.x;
y := v.y;
v.x := _matrix[0, 0]*x + _matrix[1, 0]*y;
v.y := _matrix[0, 1]*x + _matrix[1, 1]*y;
end;
constructor TRotationMatrix.Create(angle: Real);
var
pom: Real;
begin
pom := (angle / 180) * Pi;
_matrix[0, 0] := Cos(pom);
_matrix[0, 1] := -Sin(pom);
_matrix[1, 0] := Sin(pom);
_matrix[1, 1] := Cos(pom);
end;
//------------TGeneralEllipseEquation--------------
{
function TGeneralEllipseEquation.pointOnEllipse(p: TPoint): Boolean; //v podstate ani nefunguje :)
begin
Result := (((p.X - _m.point.X)/(_a*_a)) + ((p.Y - _m.point.Y)/(_b*_b))) < (1 + PRECISION);
Result := Result or (((p.X - _m.point.X)/(_a*_a)) + ((p.Y - _m.point.Y)/(_b*_b))) > (1 - PRECISION);
end; }
function TGeneralEllipseEquation.pointInEllipse(p: TPoint): Boolean;
begin
Result := (((p.X - _m.point.X)*(p.X - _m.point.X)/(_a*_a)) + ((p.Y - _m.point.Y)*(p.Y - _m.point.Y)/(_b*_b))) < 1 ;
end;
function TGeneralEllipseEquation.xToPoint(x: Real): TPrecisePoint;
var
p: Real;
begin
x := x - centre.x;
p := (1 - (x*x)/(a*a))*(b*b);
if (p < 0) then
Result := nil
else
Result := TPrecisePoint.Create(x + centre.x, sqrt(p) + centre.y);
end;
function TGeneralEllipseEquation.yToPoint(y: Real): TPrecisePoint;
var
p: Real;
begin
y := y - centre.y;
p := (1 - (y*y)/(b*b))*(a*a);
if (p < 0) then
Result := nil
else
Result := TPrecisePoint.Create(sqrt(p) + centre.x, y + centre.y);
end;
function TGeneralEllipseEquation.lineIntersection(l: TGeneralLineEquation): TPrecisePoints;
begin
Result := lineIntersection(l.a, l.b, l.c);
end;
function TGeneralEllipseEquation.lineIntersection(a, b, c: Real): TPrecisePoints;
var
k, l, x: Real;
p: TPrecisePoint;
a1, a2, a3, D, cc: Real;
begin
Result := nil;
if (abs(b) <= PRECISION) then
begin
if (a = 0) then
Exit;
k := (-c)/a;
p := xToPoint(k);
if (p <> nil) then
begin
if (p.y = 0) then
begin
SetLength(Result, 1);
Result[0] := p;
end
else
begin
SetLength(Result, 2);
Result[0] := p;
Result[1] := TPrecisePoint.Create(p.x, -p.y);
end;
end;
Exit;
end;
//ak b nieje 0
cc := c;
p := TPrecisePoint.Create(0, -c/b);
c := -(a*(p.x-centre.x)+b*(p.Y-centre.Y)); //posuneme o stred
p.Free;
k := (-a)/b;
l := ((-c)/b);
a1 := ((_a*_a)*(k*k)) + (_b*_b);
a2 := (2*k*l*(_a*_a));
a3 := ((l*l)*(_a*_a)) - ((_a*_a)*(_b*_b));
D := (a2*a2) - (4*a1*a3);
if (D < 0) then
Exit;
if (D = 0) then
begin
SetLength(Result, 1);
x := (-a2)/(2*a1);
x := x + centre.x;
Result[0] := TPrecisePoint.Create(x, ((-a*x) - c)/b);
Exit;
end;
if (D > 0) then
begin
SetLength(Result, 2);
x := ((-a2) + sqrt(D))/(2*a1);
x := x + centre.x;
Result[0] := TPrecisePoint.Create(x, ((-a*x) - cc)/b);
x := ((-a2) - sqrt(D))/(2*a1);
x := x + centre.x;
Result[1] := TPrecisePoint.Create(x, ((-a*x) - cc)/b);
Exit;
end;
end;
function TGeneralEllipseEquation.pointDistance(p: TPoint): Integer;
const
ITERATION = 100;
var
pom, it: TPrecisePoint;
poc: Integer;
great: (a, b);
begin
Result := MaxInt;
poc := 0;
if (_b > _a) then //chceme ju tak aby hlavna os bola rovnobezna z X
great := b
else
great := a;
pom := TPrecisePoint.Create(abs(p.X - centre.x), abs(p.Y - centre.y));
repeat
if (great = a) then
it := xToPoint((_a/ITERATION)*poc + centre.x)
else
it := yToPoint((_b/ITERATION)*poc + centre.y);
if (not (it = nil)) then
begin
it.x := it.x - centre.x;
it.y := it.y - centre.y;
Result := Min(Result, round(TSupport.distance(it, pom)));
it.Free;
end;
poc := poc + 1;
until poc > ITERATION;
pom.Free;
end;
function TGeneralEllipseEquation.toString(): String;
begin
Result := 'X: ' + FloatToStrF(centre.x, ffFixed, 2, 2) + ' Y: ' + FloatToStrF(centre.y, ffFixed, 2, 2) +
'majoraxis: '+ FloatToStrF(a, ffFixed, 2, 2) + ' minoraxis: '+ FloatToStrF(b, ffFixed, 2, 2);
end;
function TGeneralEllipseEquation.getPoints(): TPoints;
var
angle: Real;
i: Integer;
Ellipse_points: Integer;
begin
Ellipse_points := max(round((b+a) / 5), 30);
SetLength(Result, Ellipse_points);
for i:= 0 to Ellipse_points-1 do
begin
angle := -PI + ((PI/Ellipse_points)*(2*i));
Result[i].X := round(centre.x + a*cos(angle));
Result[i].Y := round(centre.y + b*sin(angle));
end;
end;
function TGeneralEllipseEquation.getF(): Real;
begin
Result := 1 - (b/a);
end;
constructor TGeneralEllipseEquation.Create(x, y, a, b: Real);
begin
_m := TPrecisePoint.Create(x, y);
_a := a;
_b := b;
end;
destructor TGeneralEllipseEquation.Destroy;
begin
_m.Free;
end;
//-------------------------------------------------
end.