-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalcNormalAnglesTest.m
58 lines (49 loc) · 1.49 KB
/
CalcNormalAnglesTest.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
57
58
clear; close all;
cubeVerts = ...
[1.000000, -1.000000, -1.000000; ...
1.000000, -1.000000, 1.000000; ...
-1.000000, -1.000000, 1.000000; ...
-1.000000, -1.000000, -1.000000; ...
1.000000, 1.000000, -0.999999; ...
0.999999, 1.000000, 1.000001; ...
-1.000000, 1.000000, 1.000000; ...
-1.000000, 1.000000, -1.000000];
cubeFaces = ...
[2, 3, 4; ...
8, 7, 6; ...
5, 6, 2; ...
6, 7, 3; ...
3, 7, 8; ...
1, 4, 8; ...
1, 2, 4; ...
5, 8, 6; ...
1, 5, 2; ...
2, 6, 3; ...
4, 3, 8; ...
5, 1, 8];
[vertNormals, faceNormals] = CalcNormals(cubeVerts, cubeFaces);
angles = CalcNormalAngles(cubeVerts, cubeFaces, vertNormals);
numBins = 4;
[histCounts, histEdges, histNorm] = CalcHistAngles(angles, numBins);
% Plot cube vertices.
figure;
px = cubeVerts(:, 1);
py = cubeVerts(:, 3); % . Swap the two axes so that y is up and z is forward.
pz = cubeVerts(:, 2); % ^
plot3(px, py, pz);
hold on;
plot3(px(1), py(1), pz(1), '*'); % Highlight the start vertex.
drawnow;
% Plot cube vertices offset by normal (should be a bigger cube).
cubeOffsets = cubeVerts + vertNormals * 0.2;
px = cubeOffsets(:, 1);
py = cubeOffsets(:, 3); % . Swap the two axes so that y is up and z is forward.
pz = cubeOffsets(:, 2); % ^
hold on;
plot3(px, py, pz);
hold on;
plot3(px(1), py(1), pz(1), '*'); % Highlight the start offset.
drawnow;
% Plot the histogram in a new figure.
figure;
histogram('BinEdges', histEdges, 'BinCounts', histCounts);