Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function DBSCAN(p: TPointArray; d, minPts: Integer): T2DPointArray;
- var
- v, nC: array of Boolean;
- n, n2: TIntegerArray;
- i, dL, r, ii, nL, rL, iii, nL2: Integer;
- begin
- dL := Length(p);
- SetLength(v, dL);
- SetLength(nC, dL);
- SetLength(Result, dL);
- r := 0;
- dL := dL - 1;
- for i := 0 to dL do
- begin
- v[i] := False;
- nC[i] := True;
- end;
- for i := 0 to dL do
- begin
- if (not (v[i])) then
- begin
- v[i] := True;
- SetLength(n, dL);
- nL := 0;
- for ii := 0 to dL do
- begin
- if (ii <> i) then
- if(not (v[ii])) then
- if (Distance(p[i].x, p[i].y, p[ii].x, p[ii].y) <= d) then
- begin
- n[nL] := ii;
- nL := nL + 1;
- end;
- end;
- SetLength(n, nL);
- if (nL >= minPts) then
- begin
- SetLength(Result[r], dL + 1);
- Result[r][0] := p[i];
- rL := 1;
- for ii := 0 to nL - 1 do
- begin
- if (not (v[n[ii]])) then
- begin
- v[n[ii]] := True;
- nL2 := 0;
- SetLength(n2, dL);
- for iii := 0 to dL do
- if (n[ii] <> iii) then
- if(not (v[iii])) then
- if (nC[n[ii]]) then
- if (Distance(p[n[ii]].x, p[n[ii]].y, p[iii].x, p[iii].y) <= d) then
- begin
- n2[nL2] := iii;
- nL2 := nL2 + 1;
- end;
- SetLength(n2, nL2);
- if (nL2 >= minPts) then
- begin
- SetLength(n, nL + nL2);
- for iii := nL to nL + nL2 - 1 do
- n[iii] := n2[iii - nL];
- nL := nL + nL2;
- end;
- end;
- if (nC[n[ii]]) then
- begin
- nC[n[ii]] := False;
- Result[r][rL] := p[n[ii]];
- rL := rL + 1;
- end;
- end;
- SetLength(Result[r], rL);
- r := r + 1;
- end;
- end;
- end;
- SetLength(Result, r);
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement