-
Notifications
You must be signed in to change notification settings - Fork 0
/
UPoligon.pas
50 lines (48 loc) · 1.44 KB
/
UPoligon.pas
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
Unit UPoligon;
interface
uses UCalc3D, UCalcVec, Graph;
{---------------------------------------------------------------}
type
TPoli = record n: word; P: PVecList; end;
{---------------------------------------------------------------}
function GetPoli(var Poli: TPoli; nr: word): boolean;
procedure FreePoli(var Poli: TPoli);
procedure PoliG(Var Poli: TPoli; Var G: TVec2Real);
{---------------------------------------------------------------}
implementation
{---------------------------------------------------------------}
function GetPoli(var Poli: TPoli; nr: word): boolean;
begin
with Poli do begin
GetMem(P, nr*SizeOf(Pointer));
if P = nil then n := 0 else n := nr;
GetPoli := n = nr;
end;
end;
{---------------------------------------------------------------}
procedure FreePoli(var Poli: TPoli);
begin
with Poli do begin
FreeMem(P, n*SizeOf(Pointer));
P := nil;
n := 0;
end;
end;
{---------------------------------------------------------------}
procedure PoliG(Var Poli: TPoli; Var G: TVector);
var i, j: integer;
begin
G := VecZero;
if Poli.P = nil then exit;
with Poli do for i := 0 to n - 1 do begin
if P^[i] = nil then Continue;
G[1] := G[1] + P^[i]^[1];
G[2] := G[2] + P^[i]^[2];
G[3] := G[3] + P^[i]^[3];
end;
G[1] := G[1] / Poli.n;
G[2] := G[2] / Poli.n;
G[3] := G[3] / Poli.n;
end;
{---------------------------------------------------------------}
end.