forked from jamesra/VikingPlot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CirclePatch.m
66 lines (43 loc) · 1.4 KB
/
CirclePatch.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
59
60
61
62
63
64
65
function [ verts, normals ] = CirclePatch( numPts, radius, axis )
%CIRCLEPATCH Return a Nx3 matrix defining a set of verticies around a
%unit circle
axis = axis ./ norm(axis);
step = (2*pi) / numPts;
verts = zeros(numPts,3);
normals = zeros(numPts,3);
for(theta = 0:step:(2*pi) - step)
x = cos(theta) * radius;
y = sin(theta) * radius;
z = 0;
verts(int32(theta/step)+1, :) = [x y z];
normals(int32(theta/step)+1, :) = [x y z];
end
[angle, newaxis] = AngleAndAxis([0 0 1], axis);
RotMat = RotationMatrix(angle, newaxis);
TestVector = verts(1,:);
TestVectorRot = TestVector * RotMat;
[testangle,testaxis] = AngleAndAxis(axis, TestVectorRot);
% disp(['Test Angle: ' num2str(testangle)]);
if(testangle > .0001 || testangle < .0001)
angle = pi-angle;
end
%{
if(angle > pi / 2)
%angle = angle - pi;
angle = -angle;
end
%Figure out polarity of the angle
c = cross([0 0 1], axis);
% disp(['Angle: ' num2str(angle)]);
% disp(num2str(c));
% disp(dot(c, [1 0 0]));
%Rotate the circle onto the axis
if(c(2) > 0)
angle = -angle;
end
%}
RotMat = RotationMatrix(angle, newaxis);
verts = verts * RotMat;
normals = normals * RotMat;
return
end