-
Notifications
You must be signed in to change notification settings - Fork 1
/
find_AxisByPrincipalDir_mt.m
41 lines (34 loc) · 1.17 KB
/
find_AxisByPrincipalDir_mt.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
function [ Axis ] = find_AxisByPrincipalDir_mt(pts,dir1,center,show_result)
%% find_AxisByPrincipalDir_mt 根据给定的主方向计算出坐标系
%% 函数返回值 Axis 4*3向量 Axis(1,:) 坐标原点 Axis(2,:)主方向轴 Axis(3,:)第二方向轴 Axis(4,:)第三方向轴
%% 步骤1
%% 计算所有点到主方向垂直面上的投影坐标
%ptsNum=size(pts,1);
%pCoords=zeros(ptsNum,3);
pCoords=find_ProjCoord_mt(dir1,center,pts);
coeff = pca(pCoords);
if(size(coeff,2)==3)
dir2=coeff(:,1)';
dir3=coeff(:,2)';
elseif(size(coeff,2)==2)
dir2=coeff(:,1)';
dir3=[0 0 0];
else
dir2=[0 0 0];
dir3=[0 0 0];
end
Axis=[center;dir2;dir3;dir1];
if(show_result)
figure('Name','Given Dir Plane','NumberTitle','off');set(gcf,'color','white');movegui('southwest');
scatter3(pts(:,1),pts(:,2),pts(:,3),5,[0 0 0], 'filled');
hold on;
scatter3( pCoords(:,1), pCoords(:,2), pCoords(:,3),5,[0 1 0], 'filled');
hold on;
showLine(center,dir1,'r');
showLine(center,dir2,'g');
showLine(center,dir3,'b');
%showLine(J_J_Center,GrowthDir,'b');
axis off; axis equal; camorbit(0,0,'camera'); axis vis3d; view(-90,0);view3d rot;
%showLine(xyz,dir,'r');
end
end