-
Notifications
You must be signed in to change notification settings - Fork 3
/
EquiDistant2DPoints.m
56 lines (51 loc) · 2.16 KB
/
EquiDistant2DPoints.m
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
function [UPointsVec, VPointsVec] = EquiDistant2DPoints(UArray, VArray, Diameter)
%% This function produces NP points which distributed equi-distantly on the 2D UV Coordinates
% NP is the number of points
% ULimit and VLimit are range of U and V axes in the UV coordinate, respectively.
UMax = max(UArray);
UMin = min(UArray);
UStep = sqrt(3) * Diameter / 2;
UGrid = UMin : UStep : UMax;
ULength = numel(UGrid);
VMax = max(VArray);
VMin = min(VArray);
VStep = Diameter;
VGrid = VMin : VStep : VMax;
VLength = numel(VGrid);
DistributedPoints = NaN(ULength * VLength, 2);
IndexModifier = 1;
for UCounter = 1 : 1 : ULength
StartingU = UMin + (UCounter - 1) * (sqrt(3) * Diameter / 2);
% Odd UCounter
if (mod(UCounter, 2) ~= 0)
StartingV = VMin - Diameter;
for VCounter = 1 : 1 : VLength
StartingV = StartingV + Diameter;
if StartingV > VMax
continue;
end
DistributedPoints(IndexModifier, :) = [StartingU, StartingV];
IndexModifier = IndexModifier + 1;
end
% Even UCounter
else
StartingV = VMin + Diameter / 2;
if StartingV > VMax
continue;
end
for VCounter = 1 : 1 : VLength
if StartingV > VMax
continue;
end
DistributedPoints(IndexModifier, :) = [StartingU, StartingV];
IndexModifier = IndexModifier + 1;
StartingV = StartingV + Diameter;
end
end
end
DistributedPointsUModification = (UMax - max(DistributedPoints(:, 1))) / 2;
DistributedPointsVModification = (VMax - max(DistributedPoints(:, 2))) / 2;
% Relocate the points at the center of the 2D plane
UPointsVec = DistributedPointsUModification + transpose(DistributedPoints(~isnan(DistributedPoints(:, 1)), 1));
VPointsVec = DistributedPointsVModification + transpose(DistributedPoints(~isnan(DistributedPoints(:, 2)), 2));
end