-
Notifications
You must be signed in to change notification settings - Fork 0
/
archimideanSpiral2d.m
88 lines (68 loc) · 1.88 KB
/
archimideanSpiral2d.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
clear all;
close all;
%% Saving the generated data
% Structure of the data = [X Xdot Time Subdynamic_Id]
% By default, subdynamic_Id is 1. Changes in case there are multiple
% subdynamics in the demonstrations
% Params for the demonstrations
demoCount = 1;
c = [2]; % Swirls in spiral
r = 0.1; % Radius of sphere
T = 12; % Time to make the spiral
N = [500]; % Point count per demonstration
% Other params
label = 1;
for nIndex = 1:length(N)
for cIndex = 1:length(c)
demo_struct = {'position', 'velocity', 'time', 'labels'};
demo = cell(demoCount, 1);
nVal = N(nIndex);
cVal = c(cIndex);
target = cVal*2*pi;
dT = T/nVal; % Recording frequency
%% Generating the data
for count = 1:demoCount
t = 0;
genData = [];
for pointCount = 1:nVal
tempPos = spiralPos(t,r,cVal,T);
tempVel = spiralVel(t,r,cVal,T);
genData = [genData; [tempPos, tempVel, t]];
t = t + dT;
end
genData = [genData ones(size(genData,1),1)];
demo{count} = genData';
end
name = strcat("N_",int2str(nVal),"_c_",int2str(cVal),".mat");
save(name ,'demo','demo_struct', "-mat");
end
end
%% Visualising the data
figure
for demoIndex = 1:demoCount
plot(demo{demoIndex}(1,:), demo{demoIndex}(2,:), 'r')
xlabel('x')
ylabel('y')
end
%% Helper functions
function pos = spiralPos(t,r,c,T)
target = 2*pi*c;
thetaDot = target/T;
theta = 0 + t*thetaDot;
% rad = b * theta, b = R/target
b = r/target;
rad = 0 + b*theta;
x = rad*cos(theta);
y = rad*sin(theta);
pos = [x y];
end
function vel = spiralVel(t,r,c,T)
target = 2*pi*c;
thetaDot = target/T;
theta = 0 + t*thetaDot;
b = r/target;
xDot = b*thetaDot*cos(theta) - b*theta*thetaDot*sin(theta);
yDot = b*thetaDot*sin(theta) + b*theta*thetaDot*cos(theta);
vel = [xDot yDot];
end
%%