diff --git a/ShoulderCase/@Glenoid/measureWidthAndHeightWithPCSA.m b/ShoulderCase/@Glenoid/measureWidthAndHeightWithPCSA.m new file mode 100644 index 0000000..1cb52db --- /dev/null +++ b/ShoulderCase/@Glenoid/measureWidthAndHeightWithPCSA.m @@ -0,0 +1,57 @@ +function measureWidthAndHeightWithPCSA(obj) + % Calculation of the PCA coeficient (vectors heights and width) + [coef,~]=pca(obj.surface.points); + + % Base matrix in the "PCA" referential, in the order + % height-width-depth + px = [];% empty vector used to store the dot products between the PCA axes and the scapula axes + py = []; + pz = []; + for i = 1:3 + px = [px abs(dot(coef(:,i),xAxis))]; + py = [py abs(dot(coef(:,i),yAxis))]; + pz = [pz abs(dot(coef(:,i),zAxis))]; + end + [~,a] = max(px); % Here, the width is mainly on the xAxis, + [~,b] = max(py); % height on the yAxis + [~,c] = max(pz); % and depth on the zAxis + + if a==b && a==c + a=1;b=2;c=3; + else + if a==b + if max(py)>max(px) + a=6-b-c; + else + b=6-a-c; + end + end + if a==c + if max(px)>max(pz) + c=6-a-b; + else + a=6-b-c; + end + end + if b==c + if max(py)>max(pz) + c=6-a-b; + else + b=6-a-c; + end + end + end + + NewPCAAxis = [coef(:,b),coef(:,a),coef(:,c)]; % New basis in PCA referential, columns are then in the order "height-width-depth" + PCAGlenSurf = []; + for i=1:size(obj.surface.points(:,1)) + vp = NewPCAAxis^-1 * obj.surface.points(i,:)'; + PCAGlenSurf = [PCAGlenSurf;vp']; + end + + heightPCA = max(PCAGlenSurf(:,1))-min(PCAGlenSurf(:,1)); + widthPCA = max(PCAGlenSurf(:,2))-min(PCAGlenSurf(:,2)); + + obj.height=heightPCA; + obj.width=widthPCA; +end