How can I transform 3D position coordinates from a global to a local coordinate sytem?

15 次查看(过去 30 天)
I'm stuck trying to transform 3D position coordinates from a global to a local coordinate system. My current code is below, but is incorrect and I don't know where the error is. Any help would be much appreciated.
%Marker coordinates in GCS
Marker1_GCS=[-941,549,1006];
Marker2_GCS=[-939,294,990];
Marker3_GCS=[-1127,461,1018];
Marker4_GCS=[-1127,375,1017];
%Define origin of LCS as between markers 3 and 4
origin_LCS=mean([Marker3_GCS;Marker4_GCS]);
%Define the y axis as from origin to the mean of markers 1 and 2
V=mean([Marker1_GCS;Marker2_GCS])-origin_LCS;
%The unit vector on the y axis is V/length(V) in the GCS
Y=V/sqrt((V(1)^2)+(V(2)^2)+(V(3)^2));
%Define a vector U from Marker 1 to Marker 2 as the plane of the x-axis
U=Marker2_GCS-Marker1_GCS;
%The unit vector on the Uu axis is U/length(U) in the GCS
Uu=U/sqrt((U(1)^2)+(U(2)^2)+(U(3)^2));
%Define the direction of the z axis (W) by the vector cross product of Uu and Y
W=cross(Uu,Y);
%The unit vector on the Z axis is W/length(W) in the GCS
Z=W/sqrt((W(1)^2)+(W(2)^2)+(W(3)^2));
%Define the direction of the x axis by the vector cross product of Y and Z
X=cross(Y,Z);
%Put these variables together into the transformation matrix.
%This is the transformation matrix to get from the global CS to the local pelvis coordinate system (Tgl)
%Tgl is arranged:
% Xx Yx Zx Ox
% Xy Yy Zy Oy
% Xz Yz Zz Oz
% 0 0 0 1
Tgl=[X' Y' Z' origin_LCS';0 0 0 1];
%Calculate marker coordinates in LCS
Marker1_LCS=(Tgl*[Marker1_GCS';1])';
Marker2_LCS=(Tgl*[Marker2_GCS';1])';
Marker3_LCS=(Tgl*[Marker3_GCS';1])';
Marker4_LCS=(Tgl*[Marker4_GCS';1])';
  1 个评论
Jayaram Theegala
Jayaram Theegala 2017-2-17
If you want to transform your coordinates from global to local coordinate system, you can consider using MATLAB's "global2localcoord" function. For more information about this function, click on the following URL:

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cartesian Coordinate System Conversion 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by