필터 지우기
필터 지우기

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