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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| % Program
clear all;
% Input initialisation
R=[pi/4;0;pi/2]; % Matrix with yaw, pitch and roll for the rotation matrix
T=[4;8;2]; % Translation matrix
point(1).coord=[0;0;0];
point(2).coord=[0;1000;0];
point(3).coord=[1000;1000;0];
point(4).coord=[1000;0;0];
point(5).coord=point(1).coord;
% Program code
KK=[ % Camera Matrix
20195.5365,0,1823.5; % [fc(1),alpha(c)*fc(1),cc(1)
0,20218.67258,1367.5; % 0,fc(2),cc(2)
0,0,1 % 0,0,1]
];
yaw=R(1); % X angle (rad)
pitch=R(2); % Y angle (rad)
roll=R(3); % Z angle (rad)
ROT=[
cos(yaw)*cos(pitch),-cos(roll)*sin(yaw)+cos(yaw)*sin(pitch)*sin(roll),cos(yaw)*cos(roll)*sin(pitch)+sin(yaw)*sin(roll);
cos(pitch)*sin(yaw),cos(yaw)*cos(roll)+sin(yaw)*sin(pitch)*sin(roll),cos(roll)*sin(yaw)*sin(pitch)-cos(yaw)*sin(roll);
-sin(pitch),cos(pitch)*sin(roll),cos(pitch)*cos(roll)
]; % Rotation matrix
k=length(point); % Number of point
for i=1:k
rotatepoint(i).coord=ROT*point(i).coord+T; % Point moving with rotation and translation
end
MatrixX=[]; % We create matrix for coordinate X of points after rotation and translation
MatrixY=[]; % We create matrix for coordinate Y of points after rotation and translation
MatrixZ=[]; % We create matrix for coordinate Z of points after rotation and translation
for i=1:k
MatrixX=[MatrixX; rotatepoint(i).coord(1)]; % We put X coordinates inside the matrixX
MatrixY=[MatrixY; rotatepoint(i).coord(2)]; % We put Y coordinates inside the matrixY
MatrixZ=[MatrixZ; rotatepoint(i).coord(3)]; % We put Z coordinates inside the matrixZ
end
figure
hold on
view(3)
plot3(MatrixX,MatrixY,MatrixZ),
grid,
xlabel('Axe des x')
ylabel('Axe des y')
zlabel('Axe des z')
title('Forme après rotation et translation')
% We look the rectangle in the space
for j=1:k
projectionpoint(j).coord=(1/rotatepoint(j).coord(3))*KK*rotatepoint(j).coord;
end
ProjectionmatrixX=[]; % We create matrix for coordinate X of points after rotation and translation
ProjectionmatrixY=[]; % We create matrix for coordinate Y of points after rotation and translation
ProjectionmatrixZ=[]; % We create matrix for coordinate Z of points after rotation and translation
for j=1:k
ProjectionmatrixX=[ProjectionmatrixX; projectionpoint(j).coord(1)]; % We put X coordinates inside the matrixX
ProjectionmatrixY=[ProjectionmatrixY; projectionpoint(j).coord(2)]; % We put Y coordinates inside the matrixY
ProjectionmatrixZ=[ProjectionmatrixZ; projectionpoint(j).coord(3)]; % We put Z coordinates inside the matrixZ
end
plot3(ProjectionmatrixX,ProjectionmatrixY,ProjectionmatrixZ),
% grid,
% xlabel('Axe des x')
% ylabel('Axe des y')
% zlabel('Axe des z')
% title('Forme après toutes les corrections')
% We look the rectangle in the space camera |
Partager