Static Matlab file to calculate constant parameters from Vicon static trial.
In input a Static.csv file is given which contains: xyz coordinates of: ASIS anterior and posterior, hip, knee and ankle joint centres, mid foot and heel markers.

As output leg segment lengths and foot segments lengths are calculated. Alpha and beta, angles at the rear and front part of the foot, are also calculated.
________________________________________________________________
STA = csvread('Static.csv');
%Input xyz coordinates from static trial
%Input are corrected for the different convention used by Vicon so it will
%result in z lateral positive to the right and y vertical
RASIS = STA(1,1:3);
RPSIS = STA(1,4:6);
LASIS = STA(1,10:12);
LPSIS = STA(1,7:9);
LHJC= STA(1,13:15);
LKJC= STA(1,16:18);
LAJC= STA(1,19:21);
LmidFOOT = STA(1,22:24);
LHEEL = STA(1,25:27);
RHJC = STA(1,28:30);
RKJC = STA(1,31:33);
RAJC = STA(1,34:36);
RmidFOOT = STA(1,37:39);
RHEEL = STA(1,40:42);
SACR = (LPSIS+RPSIS)/2;
PELF = (LASIS+RASIS)/2;

% determine the position of CM approximation
a = RPSIS(1,1) - LASIS(1,1);
b = - (LPSIS(1,1) - RASIS(1,1));
d = (-RPSIS(1,2)) - (-LASIS(1,2));
e = - (-(LPSIS(1,2)) - (-RASIS(1,2)));
c = RASIS(1,1) - LASIS(1,1);
f = (-RASIS(1,2)) - (-LASIS(1,2));
A = [ a b; d e];
B = [c;f]; 
X = linsolve(A,B);
v1 = X(2,1);
v2 = X(1,1);
% x and z coordinates calculated from the intersection between LASIS-RPSIS
% line and RASIS-LPSIS line
CMx = LASIS(1,1) + v2* a;
CMz = -LASIS(1,2) + v2* d;
% y coordinate obtained from the projection of the CM point in to the
% PELF-SACR line
R = (CMx-PELF(1,1))/(SACR(1,1)-PELF(1,1));
CMy= R*(SACR(1,3)-PELF(1,3))+PELF(1,3);

% b = LPSIS(1,1) - RASIS(1,1);
% e = LPSIS(1,2) - RASIS(1,2);
% A = [1/d -1/a; 1/e -1/b];
% B = [(LASIS(1,2)/d)-(LASIS(1,1)/a); (RASIS(1,2)/e)-(RASIS(1,1)/b)];
% X = linsolve(A,B);


%Left leg segment distance
LHx = LHEEL(1,1);
LHy = LHEEL(1,3);
LMx = LmidFOOT(1,1);
LMy = LmidFOOT(1,3);
LAx = LAJC (1,1);
LAy = LAJC (1,3);
LKx = LKJC (1,1);
LKy = LKJC (1,3);
LHIx = LHJC (1,1);
LHIy = LHJC (1,3);

LHM = sqrt((LMx-LHx)^2 + (LMy-LHy)^2); %sole of the foot
LHA = sqrt((LAx-LHx)^2 + (LAy-LHy)^2); % heel to ankle distance
LAM = sqrt((LAx-LMx)^2 + (LAy-LMy)^2); % toe to ankle distance
LAK = sqrt((LKx-LAx)^2 + (LKy-LAy)^2); %ankle to knee segment
LKH = sqrt((LHIx-LKx)^2 + (LHIy-LKy)^2); % knee to hip segment
LHCM = sqrt((CMx-LHIx)^2 + (CMy-LHIy)^2);% hip to CM segment

P = ((LAx-LHx)/LHA)* ((LMx-LHx)/LHM)+((LAy-LHy)/LHA)*((LMy-LHy)/LHM);
Lalpha = acos (P); % Heel angle 
C = ((LAx-LMx)/LAM)* ((LHx-LMx)/LHM)+((LAy-LMy)/LAM)*((LHy-LMy)/LHM);
Lbeta = acos (C); % Toe angle 

JJ=[LHM LAM LAK LKH LHCM Lalpha Lbeta LHA];
csvwrite ('StaticvaluesL.csv',JJ,0,0);

%Right leg segment distance
RHx =RHEEL(1,1);
RHy =RHEEL(1,3);
RMx = RmidFOOT(1,1);
RMy = RmidFOOT(1,3);
RAx = RAJC (1,1);
RAy = RAJC (1,3);
RKx = RKJC (1,1);
RKy = RKJC (1,3);
RHIx = RHJC (1,1);
RHIy = RHJC (1,3);

RHM = sqrt((RMx-RHx)^2 + (RMy-RHy)^2); %sole of the foot
RHA = sqrt((RAx-RHx)^2 + (RAy-RHy)^2); % heel to ankle distance
RAM = sqrt((RAx-RMx)^2 + (RAy-RMy)^2); % toe to ankle distance
RAK = sqrt((RKx-RAx)^2 + (RKy-RAy)^2); %ankle to knee segment
RKH = sqrt((RHIx-RKx)^2 + (RHIy-RKy)^2); % knee to hip segment
RHCM = sqrt((CMx-RHIx)^2 + (CMy-RHIy)^2);

Q = ((RAx-RHx)/RHA)* ((RMx-RHx)/RHM)+((RAy-RHy)/RHA)*((RMy-RHy)/RHM);
Ralpha = acos (Q);
D = ((RAx-RMx)/RAM)* ((RHx-RMx)/RHM)+((RAy-RMy)/RAM)*((RHy-RMy)/RHM);
Rbeta = acos (D); % Toe angle 

KK=[RHM RAM RAK RKH RHCM Ralpha Rbeta RHA];
csvwrite ('StaticvaluesR.csv',KK,0,0);