function [AnimationFigure] = SimulationVraag5Function(TDnumber,condition,trialnumber,tibialength,x_knee,y_knee)
SimulationVraag5Video = VideoWriter('SimulationVraag5Video.avi');
open(SimulationVraag5Video);
startpath ='/MATLAB Drive/Assignment_V2/MBEXAMEN/EXAMEN/Data';
Datapath = [startpath '/Data'];
addpath '/MATLAB Drive/Assignment_V2/MBEXAMEN/EXAMEN'
if condition == 1
for i = TDnumber
dataFolder = [startpath '/TD' num2str(i)];
dataFile = fullfile(dataFolder, '/IK/HR*.mot');
pathwayIK_HR = dir(dataFile);
if i == 3 | i == 5 | i == 7 | i == 9 | i == 14
x_hip = x_knee+30
y_hip = y_knee+10
x_shoulder = x_knee+35;
y_shoulder = y_knee+50;
x_midhead = x_knee+35;
y_midhead = y_knee+60;
dataFolder = [startpath '/TD' num2str(i)];
for k = trialnumber
IKHRdata = importdata(fullfile(pathwayIK_HR(k).folder,pathwayIK_HR(k).name));
DataHRlinks = IKHRdata.data(:,strcmp('knee_angle_l',IKHRdata.colheaders));
TimeHRlinks = IKHRdata.data(:,strcmp('time',IKHRdata.colheaders));
kneeangle = IKHRdata.data(:,strcmp('knee_angle_l',IKHRdata.colheaders))
for a = 1:100:length(kneeangle)
lengthbetweenkneehip = sqrt(((x_knee-x_hip)^2) + (y_knee-y_hip)^2)
lengthbetweenanklehip = sqrt(tibialength^2 + lengthbetweenkneehip^2 - (2*tibialength * lengthbetweenkneehip * cos(kneeangle(a))))
lengthbetweenanklehipsquared = lengthbetweenanklehip^2
lengthbetweenkneeankle = tibialength
lengthbetweenkneeanklesquared = tibialength^2
syms x_ankle y_ankle
E = [((x_hip-x_ankle)^2 + (y_hip-y_ankle)^2 - lengthbetweenanklehipsquared == 0), ((x_knee-x_ankle)^2 + (y_knee-y_ankle)^2 - lengthbetweenkneeanklesquared == 0)];
S = solve(E,x_ankle,y_ankle)
x_ankle = S.x_ankle
y_ankle = S.y_ankle
x(1) = x_knee
x(2) = x_ankle(1)
y(1) = y_knee
y(2) = y_ankle(1)
xlim([-100 100]);
ylim([-100 100]);
hold on;
plot(x_hip,y_hip,'o');
plot([x_hip x_knee], [y_hip y_knee])
text(x_hip,y_hip,'H')
plot(x_shoulder,y_shoulder,'o');
plot([x_shoulder x_hip],[y_shoulder y_hip])
text(x_shoulder,y_shoulder,'S')
plot([x_shoulder x_midhead],[y_shoulder y_midhead])
plot(x_midhead,y_midhead,'o','linewidth',20)
text(x(1),y(1),'K')
text(x(2),y(2),'E')
grid on;
plot(x,y)
comet(x,y)
frame = getframe(gcf);
writeVideo(SimulationVraag5Video,frame);
end
end
else
x_hip = x_knee-30
y_hip = y_knee+10
x_shoulder = x_knee-35;
y_shoulder = y_knee+50;
x_midhead = x_knee-35;
y_midhead = y_knee+60;
for k = trialnumber
IKHRdata = importdata(fullfile(pathwayIK_HR(k).folder,pathwayIK_HR(k).name));
DataHRlinks = IKHRdata.data(:,strcmp('knee_angle_r',IKHRdata.colheaders));
TimeHRlinks = IKHRdata.data(:,strcmp('time',IKHRdata.colheaders));
kneeangle = IKHRdata.data(:,strcmp('knee_angle_r',IKHRdata.colheaders))
end
for a = 1:100:length(kneeangle)
lengthbetweenkneehip = sqrt(((x_knee-x_hip)^2) + (y_knee-y_hip)^2)
lengthbetweenanklehip = sqrt(tibialength^2 + lengthbetweenkneehip^2 - (2*tibialength * lengthbetweenkneehip * cos(kneeangle(a))))
lengthbetweenanklehipsquared = lengthbetweenanklehip^2
lengthbetweenkneeankle = tibialength
lengthbetweenkneeanklesquared = tibialength^2
syms x_ankle y_ankle
E = [((x_hip-x_ankle)^2 + (y_hip-y_ankle)^2 - lengthbetweenanklehipsquared == 0), ((x_knee-x_ankle)^2 + (y_knee-y_ankle)^2 - lengthbetweenkneeanklesquared == 0)];
S = solve(E,x_ankle,y_ankle)
x_ankle = S.x_ankle
y_ankle = S.y_ankle
x(1) = x_knee
x(2) = x_ankle(1)
y(1) = y_knee
y(2) = y_ankle(1)
xlim([-100 100]);
ylim([-100 100]);
hold on;
plot(x_hip,y_hip,'o');
plot([x_hip x_knee], [y_hip y_knee])
text(x_hip,y_hip,'H')
plot(x_shoulder,y_shoulder,'o');
plot([x_shoulder x_hip],[y_shoulder y_hip])
text(x_shoulder,y_shoulder,'S')
plot([x_shoulder x_midhead],[y_shoulder y_midhead])
plot(x_midhead,y_midhead,'o','linewidth',20)
plot(x,y);
text(x(1),y(1),'K')
text(x(2),y(2),'E')
grid on;
comet(x,y);
frame = getframe(gcf);
writeVideo(SimulationVraag5Video,frame);
end
end
end
end
if condition == 0
for i = TDnumber
dataFolder = [startpath '/TD' num2str(i)];
dataFile = fullfile(dataFolder, '/IK/MR*.mot');
pathwayIK_MR = dir(dataFile);
if i == 3 | i == 5 | i == 7 | i == 9 | i == 14
x_hip = x_knee+30
y_hip = y_knee+10
x_shoulder = x_knee+35;
y_shoulder = y_knee+50;
x_midhead = x_knee+35;
y_midhead = y_knee+60;
for k = trialnumber
IKMRdata = importdata(fullfile(pathwayIK_MR(k).folder,pathwayIK_MR(k).name));
DataMRlinks = IKMRdata.data(:,strcmp('knee_angle_l',IKMRdata.colheaders));
TimeMRlinks = IKMRdata.data(:,strcmp('time',IKMRdata.colheaders));
kneeangle = IKMRdata.data(:,strcmp('knee_angle_l',IKMRdata.colheaders));
end
for a = 1:30:length(kneeangle)
lengthbetweenkneehip = sqrt(((x_knee-x_hip)^2) + (y_knee-y_hip)^2)
lengthbetweenanklehip = sqrt(tibialength^2 + lengthbetweenkneehip^2 - (2*tibialength * lengthbetweenkneehip * cos(kneeangle(a))))
lengthbetweenanklehipsquared = lengthbetweenanklehip^2
lengthbetweenkneeankle = tibialength
lengthbetweenkneeanklesquared = tibialength^2
syms x_ankle y_ankle
E = [((x_hip-x_ankle)^2 + (y_hip-y_ankle)^2 - lengthbetweenanklehipsquared == 0), ((x_knee-x_ankle)^2 + (y_knee-y_ankle)^2 - lengthbetweenkneeanklesquared == 0)];
S = solve(E,x_ankle,y_ankle)
x_ankle = S.x_ankle
y_ankle = S.y_ankle
x(1) = x_knee
x(2) = x_ankle(1)
y(1) = y_knee
y(2) = y_ankle(1)
xlim([-100 100]);
ylim([-100 100]);
hold on;
plott = plot(x,y);
grid on;
comet(x,y);
frame = getframe(gcf);
writeVideo(SimulationVraag5Video,frame);
end
else
x_hip = x_knee-30
y_hip = y_knee+10
x_shoulder = x_knee-35;
y_shoulder = y_knee+50;
x_midhead = x_knee-35;
y_midhead = y_knee+60;
for k = trialnumber
IKMRdata = importdata(fullfile(pathwayIK_MR(k).folder,pathwayIK_MR(k).name));
DataMRlinks = IKMRdata.data(:,strcmp('knee_angle_r',IKMRdata.colheaders));
TimeMRlinks = IKMRdata.data(:,strcmp('time',IKMRdata.colheaders));
kneeangle = IKMRdata.data(:,strcmp('knee_angle_r',IKMRdata.colheaders));
end
for a = 1:30:length(kneeangle)
lengthbetweenkneehip = sqrt(((x_knee-x_hip)^2) + (y_knee-y_hip)^2)
lengthbetweenanklehip = sqrt(tibialength^2 + lengthbetweenkneehip^2 - (2*tibialength * lengthbetweenkneehip * cos(kneeangle(a))))
lengthbetweenanklehipsquared = lengthbetweenanklehip^2
lengthbetweenkneeankle = tibialength
lengthbetweenkneeanklesquared = tibialength^2
syms x_ankle y_ankle
E = [((x_hip-x_ankle)^2 + (y_hip-y_ankle)^2 - lengthbetweenanklehipsquared == 0), ((x_knee-x_ankle)^2 + (y_knee-y_ankle)^2 - lengthbetweenkneeanklesquared == 0)];
S = solve(E,x_ankle,y_ankle)
x_ankle = S.x_ankle
y_ankle = S.y_ankle
x(1) = x_knee
x(2) = x_ankle(1)
y(1) = y_knee
y(2) = y_ankle(1)
xlim([-100 100]);
ylim([-100 100]);
hold on;
plott = plot(x,y);
grid on;
comet(x,y);
frame = getframe(gcf);
writeVideo(SimulationVraag5Video,frame);
end
end
end
end
close(SimulationVraag5Video);