Last active
February 16, 2021 07:43
-
-
Save tushev/b5c162c059b5e1c0011809ae0e871015 to your computer and use it in GitHub Desktop.
Unity2MATLAB: Simple (although not-intuitive) conversion of coordinates and rotations from left-handed coordinate system (used by Unity) to right-handed (used by camera calibration toolbox in MATLAB\Octave)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function coords = L2R_coordinates(Lcoords) | |
if size(Lcoords,1) > 0 | |
if size(Lcoords,2) > 1 | |
x = Lcoords(:,1); | |
y = Lcoords(:,2); | |
z = Lcoords(:,3); | |
else | |
x = Lcoords(1); | |
y = Lcoords(2); | |
z = Lcoords(3); | |
end | |
coords = [x z y]; | |
else | |
coords = []; | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rvecs = LE2R_rodrigues(LE_angles) | |
rvecs = zeros(size(LE_angles)); | |
for i = 1:size(LE_angles,1) | |
if size(LE_angles,2) > 1 | |
aux = LE_angles(i,1); | |
auy = LE_angles(i,2); | |
auz = LE_angles(i,3); | |
else | |
aux = LE_angles(1); | |
auy = LE_angles(2); | |
auz = LE_angles(3); | |
end | |
ax = -aux; | |
ay = -auz; | |
az = -auy; | |
RX = rotX(ax); | |
RY = rotY(ay); | |
RZ = rotZ(az); | |
R = RZ*RX*RY; | |
if size(LE_angles,2) > 1 | |
rvecs(i,:) = rodrigues(R); | |
else | |
rvecs = rodrigues(R); | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function U = rotX(a) | |
U = [ 1 0 0 | |
0 cosd(a) -sind(a); | |
0 sind(a) cosd(a); ]; | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function U = rotY(a) | |
U = [ cosd(a) 0 sind(a); | |
0 1 0 | |
-sind(a) 0 cosd(a); ]; | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function U = rotZ(a) | |
U = [ cosd(a) -sind(a) 0; | |
sind(a) cosd(a) 0; | |
0 0 1 ]; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment