0% found this document useful (0 votes)
22 views3 pages

All All 'Enter Axis:' 'S' 'Enter Angle in Degrees:': Function If

The document contains MATLAB code that defines functions to perform rotation and transformation matrix calculations. It takes user input for rotation/transformation angles and axes. It applies rotation and transformation matrices to example coordinate vectors and plots the results.

Uploaded by

verkel23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

All All 'Enter Axis:' 'S' 'Enter Angle in Degrees:': Function If

The document contains MATLAB code that defines functions to perform rotation and transformation matrix calculations. It takes user input for rotation/transformation angles and axes. It applies rotation and transformation matrices to example coordinate vectors and plots the results.

Uploaded by

verkel23
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Question 3

clc
clear all
close all
ax=input('Enter Axis :','s');
ang=input('Enter Angle in degrees :');
ang=ang*pi/180.0;
ax
ang
r=rot(ax,ang);
r
function r=rot(ax,ang)

if(ax=='x')
r(1,1)=cos(ang); r(1,2)=(-1)*sin(ang); r(1,3)=0;
r(2,1)=sin(ang); r(2,2)=cos(ang); r(2,3)=0;
r(3,1)=0; r(3,2)=0; r(3,3)=1;

elseif(ax=='y')
r(1,1)=cos(ang); r(1,2)=0; r(1,3)=sin(ang);
r(2,1)=0; r(2,2)=1; r(2,3)=0;
r(3,1)=(-1)*sin(ang); r(3,2)=0; r(3,3)=cos(ang);
else
r(1,1)=1; r(1,2)=0; r(1,3)=0;
r(2,1)=0; r(2,2)=cos(ang); r(2,3)=(-1)*sin(ang);
r(3,1)=0; r(3,2)=sin(ang); r(3,3)=cos(ang);
end
end
using program for question 1 and 2:
clc
clear all
close all

a1=[1 0 0;0 0 0;0 0 0];


a2=[0 0 0;0 1 0;0 0 0];
a3=[0 0 0;0 0 0;0 0 1];
plot3(a1,a2,a3);
hold on
t1=rot('y',30);
t2=rot('x',45);
t3=t1*t2;
fprintf('The transform for Question 1 is:');
t3
t4=rot('z',30);
t5=rot('x',45);
t6=t4*t5;
fprintf('The transform for question 2 is :');
t6
a1=a1*t3;
a2=a2*t3;a3=a3*t3;
plot3(a1,a2,a3)
function r=rot(ax,ang)
ang=ang*pi/180;
if(ax=='x')
r(1,1)=cos(ang); r(1,2)=(-1)*sin(ang); r(1,3)=0;
r(2,1)=sin(ang); r(2,2)=cos(ang); r(2,3)=0;
r(3,1)=0; r(3,2)=0; r(3,3)=1;

elseif(ax=='y')
r(1,1)=cos(ang); r(1,2)=0; r(1,3)=sin(ang);
r(2,1)=0; r(2,2)=1; r(2,3)=0;
r(3,1)=(-1)*sin(ang); r(3,2)=0; r(3,3)=cos(ang);
else
r(1,1)=1; r(1,2)=0; r(1,3)=0;
r(2,1)=0; r(2,2)=cos(ang); r(2,3)=(-1)*sin(ang);
r(3,1)=0; r(3,2)=sin(ang); r(3,3)=cos(ang);
end
end
Question 6:
clc
close all
clear all
a=input('Enter angle alpha:');
b=input('Enter angle beta:');
c=input('Enter angle gamma:');
px=input('Enter px:');
py=input('Enter py:');
pz=input('Enter pz:');
t=trans(a,b,c,px,py,pz);
fprintf('The transform is :');
t
function t=trans(a,b,c,px,py,pz)
a=a*pi/180;b=b*pi/180;c=c*pi/180;

t(1,1)=cos(a)*cos(b); t(1,2)=cos(a)*sin(b)*sin(c)-sin(a)*cos(c);
t(1,3)=cos(a)*sin(b)*cos(c)+sin(a)*sin(c);t(1,4)=px;
t(2,1)=sin(a)*cos(b); t(2,2)=sin(a)*sin(b)*sin(c)+cos(a)*cos(c);
t(2,3)=sin(a)*sin(b)*cos(c)-cos(a)*sin(c);t(2,4)=py;
t(3,1)=(-1)*sin(b); t(3,2)=cos(b)*sin(c); t(3,3)=cos(b)*cos(c);t(3,4)=pz;
t(4,1)=0;t(4,2)=0;t(4,3)=0;t(4,4)=1;
end

You might also like