0% found this document useful (0 votes)
110 views

Matlab Code For Robotic Arm

The document contains Matlab code that defines points in 3D space and connects them with lines to form shapes. It applies 3D transformations - translation, rotation, and projection - to the points and animates the changing shapes over time. Functions are defined to perform the transformations, taking an input matrix of old point positions and returning a new matrix with the transformed point positions.
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)
110 views

Matlab Code For Robotic Arm

The document contains Matlab code that defines points in 3D space and connects them with lines to form shapes. It applies 3D transformations - translation, rotation, and projection - to the points and animates the changing shapes over time. Functions are defined to perform the transformations, taking an input matrix of old point positions and returning a new matrix with the transformed point positions.
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/ 23

Lab Exam

Problem Statement

Matlab Code
clc
close all
clear all
ax = 0;
ay = 0;
az = 0;
bx = 0;
by = 0;
bz = 1;
cx = 1;
cy = 0;
cz = 1;
dx = 1;
dy = 0;
dz = 0;
ex = 1;
ey = 1;
ez = 0;
fx = 0;
fy = 1;
fz = 0;
gx = 0;
gy = 1;
gz = 1;
hx = 1;
hy = 1;
hz = 1;
plot3([ax,bx],[ay,by],[az,bz],'k')
axis([-5 10 -5 10 -5 10])
hold on
plot3([bx,cx],[by,cy],[bz,cz],'k')
hold on
plot3([cx,dx],[cy,dy],[cz,dz],'k')
hold on
plot3([dx,ax],[dy,ay],[dz,az],'k')
hold on
plot3([cx,hx],[cy,hy],[cz,hz],'k')
hold on
plot3([bx,gx],[by,gy],[bz,gz],'k')
hold on
plot3([dx,ex],[dy,ey],[dz,ez],'k')
hold on
plot3([ax,fx],[ay,fy],[az,fz],'k')
hold on
plot3([ex,fx],[ey,fy],[ez,fz],'k')
hold on
plot3([fx,gx],[fy,gy],[fz,gz],'k')
hold on
plot3([gx,hx],[gy,hy],[gz,hz],'k')
hold on
plot3([hx,ex],[hy,ey],[hz,ez],'k')
hold on
text(ax,ay,az,'A','fontsize',10)
text(bx,by,bz,'B','fontsize',10)
text(cx,cy,cz,'C','fontsize',10)
text(dx,dy,dz,'D','fontsize',10)
text(ex,ey,ez,'E','fontsize',10)
text(fx,fy,fz,'F','fontsize',10)
text(gx,gy,gz,'G','fontsize',10)
text(hx,hy,hz,'H','fontsize',10)
tx=9;
ty=8;
tz=1;
ux=8;
uy=9;
uz=1;
vx=7;
vy=8;
vz=1;
wx=8;
wy=7;
wz=1;
px=9;
py=8;
pz=0;
qx=8;
qy=9;
qz=0;
rx=7;
ry=8;
rz=0;
sx=8;
sy=7;
sz=0;
plot3([tx,ux],[ty,uy],[tz,uz],'b')
axis([-5 10 -5 10 -5 10])
hold on
plot3([ux,wx],[uy,wy],[uz,wz],'b')
hold on
plot3([vx,wx],[vy,wy],[vz,wz],'b')
hold on
plot3([vx,tx],[vy,ty],[vz,tz],'b')
hold on
plot3([px,qx],[py,qy],[pz,qz],'b')
hold on
plot3([qx,sx],[qy,sy],[qz,sz],'b')
hold on
plot3([sx,rx],[sy,ry],[sz,rz],'b')
hold on
plot3([rx,px],[ry,py],[rz,pz],'b')
hold on
plot3([px,tx],[py,ty],[pz,tz],'b')
hold on
plot3([rx,vx],[ry,vy],[rz,vz],'b')
hold on
plot3([qx,ux],[qy,uy],[qz,uz],'b')
hold on
plot3([sx,wx],[sy,wy],[sz,wz],'b')
hold on
text(tx,ty,tz,'T','fontsize',10)
text(ux,uy,uz,'U','fontsize',10)
text(vx,vy,vz,'V','fontsize',10)
text(wx,wy,wz,'W','fontsize',10)
text(px,py,pz,'P','fontsize',10)
text(qx,qy,qz,'Q','fontsize',10)
text(rx,ry,rz,'R','fontsize',10)
text(sx,sy,sz,'S','fontsize',10)
Aold = [ax;ay;az;1];
Bold = [bx;by;bz;1];
Cold = [cx;cy;cz;1];
Dold = [dx;dy;dz;1];
Eold = [ex;ey;ez;1];
Fold = [fx;fy;fz;1];
Gold = [gx;gy;gz;1];
Hold = [hx;hy;hz;1];
OldPos = [Aold,Bold,Cold,Dold,Eold,Fold,Gold,Hold];
NewPos= trans3d(1,OldPos);
Axnew = NewPos(1,1);
Aynew = NewPos(2,1);
Aznew = NewPos(3,1);
Bxnew = NewPos(1,2);
Bynew = NewPos(2,2);
Bznew = NewPos(3,2);
Cxnew = NewPos(1,3);
Cynew = NewPos(2,3);
Cznew = NewPos(3,3);
Dxnew = NewPos(1,4);
Dynew = NewPos(2,4);
Dznew = NewPos(3,4);
Exnew = NewPos(1,5);
Eynew = NewPos(2,5);
Eznew = NewPos(3,5);
Fxnew = NewPos(1,6);
Fynew = NewPos(2,6);
Fznew = NewPos(3,6);
Gxnew = NewPos(1,7);
Gynew = NewPos(2,7);
Gznew = NewPos(3,7);
Hxnew = NewPos(1,8);
Hynew = NewPos(2,8);
Hznew = NewPos(3,8);
plot3([Axnew,Bxnew],[Aynew,Bynew],[Aznew,Bznew],'r')
axis([-5 10 -5 10 -5 10])
hold on
plot3([Bxnew,Cxnew],[Bynew,Cynew],[Bznew,Cznew],'r')
hold on
plot3([Cxnew,Dxnew],[Cynew,Dynew],[Cznew,Dznew],'r')
hold on
plot3([Dxnew,Axnew],[Dynew,Aynew],[Dznew,Aznew],'r')
hold on
plot3([Cxnew,Hxnew],[Cynew,Hynew],[Cznew,Hznew],'r')
hold on
plot3([Bxnew,Gxnew],[Bynew,Gynew],[Bznew,Gznew],'r')
hold on
plot3([Dxnew,Exnew],[Dynew,Eynew],[Dznew,Eznew],'r')
hold on
plot3([Axnew,Fxnew],[Aynew,Fynew],[Aznew,Fznew],'r')
hold on
plot3([Exnew,Fxnew],[Eynew,Fynew],[Eznew,Fznew],'r')
hold on
plot3([Fxnew,Gxnew],[Fynew,Gynew],[Fznew,Gznew],'r')
hold on
plot3([Gxnew,Hxnew],[Gynew,Hynew],[Gznew,Hznew],'r')
hold on
plot3([Hxnew,Exnew],[Hynew,Eynew],[Hznew,Eznew],'r')
hold on
text(Axnew,Aynew,Aznew,'A','fontsize',10)
text(Bxnew,Bynew,Bznew,'B','fontsize',10)
text(Cxnew,Cynew,Cznew,'C','fontsize',10)
text(Dxnew,Dynew,Dznew,'D','fontsize',10)
text(Exnew,Eynew,Eznew,'E','fontsize',10)
text(Fxnew,Fynew,Fznew,'F','fontsize',10)
text(Gxnew,Gynew,Gznew,'G','fontsize',10)
text(Hxnew,Hynew,Hznew,'H','fontsize',10)
OldPos = NewPos;
NewPos= trans3d(2,OldPos);
Axnew = NewPos(1,1);
Aynew = NewPos(2,1);
Aznew = NewPos(3,1);
Bxnew = NewPos(1,2);
Bynew = NewPos(2,2);
Bznew = NewPos(3,2);
Cxnew = NewPos(1,3);
Cynew = NewPos(2,3);
Cznew = NewPos(3,3);
Dxnew = NewPos(1,4);
Dynew = NewPos(2,4);
Dznew = NewPos(3,4);
Exnew = NewPos(1,5);
Eynew = NewPos(2,5);
Eznew = NewPos(3,5);
Fxnew = NewPos(1,6);
Fynew = NewPos(2,6);
Fznew = NewPos(3,6);
Gxnew = NewPos(1,7);
Gynew = NewPos(2,7);
Gznew = NewPos(3,7);
Hxnew = NewPos(1,8);
Hynew = NewPos(2,8);
Hznew = NewPos(3,8);
plot3([Axnew,Bxnew],[Aynew,Bynew],[Aznew,Bznew],'r')
axis([-5 10 -5 10 -5 10])
hold on
plot3([Bxnew,Cxnew],[Bynew,Cynew],[Bznew,Cznew],'r')
hold on
plot3([Cxnew,Dxnew],[Cynew,Dynew],[Cznew,Dznew],'r')
hold on
plot3([Dxnew,Axnew],[Dynew,Aynew],[Dznew,Aznew],'r')
hold on
plot3([Cxnew,Hxnew],[Cynew,Hynew],[Cznew,Hznew],'r')
hold on
plot3([Bxnew,Gxnew],[Bynew,Gynew],[Bznew,Gznew],'r')
hold on
plot3([Dxnew,Exnew],[Dynew,Eynew],[Dznew,Eznew],'r')
hold on
plot3([Axnew,Fxnew],[Aynew,Fynew],[Aznew,Fznew],'r')
hold on
plot3([Exnew,Fxnew],[Eynew,Fynew],[Eznew,Fznew],'r')
hold on
plot3([Fxnew,Gxnew],[Fynew,Gynew],[Fznew,Gznew],'r')
hold on
plot3([Gxnew,Hxnew],[Gynew,Hynew],[Gznew,Hznew],'r')
hold on
plot3([Hxnew,Exnew],[Hynew,Eynew],[Hznew,Eznew],'r')
hold on
text(Axnew,Aynew,Aznew,'A','fontsize',10)
text(Bxnew,Bynew,Bznew,'B','fontsize',10)
text(Cxnew,Cynew,Cznew,'C','fontsize',10)
text(Dxnew,Dynew,Dznew,'D','fontsize',10)
text(Exnew,Eynew,Eznew,'E','fontsize',10)
text(Fxnew,Fynew,Fznew,'F','fontsize',10)
text(Gxnew,Gynew,Gznew,'G','fontsize',10)
text(Hxnew,Hynew,Hznew,'H','fontsize',10)
OldPos = NewPos;
NewPos= trans3d(3,OldPos);
Axnew = NewPos(1,1);
Aynew = NewPos(2,1);
Aznew = NewPos(3,1);
Bxnew = NewPos(1,2);
Bynew = NewPos(2,2);
Bznew = NewPos(3,2);
Cxnew = NewPos(1,3);
Cynew = NewPos(2,3);
Cznew = NewPos(3,3);
Dxnew = NewPos(1,4);
Dynew = NewPos(2,4);
Dznew = NewPos(3,4);
Exnew = NewPos(1,5);
Eynew = NewPos(2,5);
Eznew = NewPos(3,5);
Fxnew = NewPos(1,6);
Fynew = NewPos(2,6);
Fznew = NewPos(3,6);
Gxnew = NewPos(1,7);
Gynew = NewPos(2,7);
Gznew = NewPos(3,7);
Hxnew = NewPos(1,8);
Hynew = NewPos(2,8);
Hznew = NewPos(3,8);
plot3([Axnew,Bxnew],[Aynew,Bynew],[Aznew,Bznew],'m')
axis([-5 10 -5 10 -5 10])
hold on
plot3([Bxnew,Cxnew],[Bynew,Cynew],[Bznew,Cznew],'m')
hold on
plot3([Cxnew,Dxnew],[Cynew,Dynew],[Cznew,Dznew],'m')
hold on
plot3([Dxnew,Axnew],[Dynew,Aynew],[Dznew,Aznew],'m')
hold on
plot3([Cxnew,Hxnew],[Cynew,Hynew],[Cznew,Hznew],'m')
hold on
plot3([Bxnew,Gxnew],[Bynew,Gynew],[Bznew,Gznew],'r')
hold on
plot3([Dxnew,Exnew],[Dynew,Eynew],[Dznew,Eznew],'m')
hold on
plot3([Axnew,Fxnew],[Aynew,Fynew],[Aznew,Fznew],'m')
hold on
plot3([Exnew,Fxnew],[Eynew,Fynew],[Eznew,Fznew],'m')
hold on
plot3([Fxnew,Gxnew],[Fynew,Gynew],[Fznew,Gznew],'m')
hold on
plot3([Gxnew,Hxnew],[Gynew,Hynew],[Gznew,Hznew],'m')
hold on
plot3([Hxnew,Exnew],[Hynew,Eynew],[Hznew,Eznew],'m')
hold on
text(Axnew,Aynew,Aznew,'A','fontsize',10)
text(Bxnew,Bynew,Bznew,'B','fontsize',10)
text(Cxnew,Cynew,Cznew,'C','fontsize',10)
text(Dxnew,Dynew,Dznew,'D','fontsize',10)
text(Exnew,Eynew,Eznew,'E','fontsize',10)
text(Fxnew,Fynew,Fznew,'F','fontsize',10)
text(Gxnew,Gynew,Gznew,'G','fontsize',10)
text(Hxnew,Hynew,Hznew,'H','fontsize',10)

function [newpoint] = trans3d(type,oldpoint)

if type == 1 % Translation
p = 7.5;
q = 7.5;
r = -0.5;
TRANS = [1 0 0 p;...
0 1 0 q;...
0 0 1 r;...
0 0 0 1];
MAT = TRANS;

elseif type == 2 % Rotation


theta = 45;
ROT = [cosd(theta) -sind(theta) 0 0;...
sind(theta) cosd(theta) 0 0;...
0 0 1 0;...
0 0 0 1];
MAT = ROT;
elseif type == 3 % Projection on xy plane
PROJXY = [0 0 0 0;...
0 1 0 0;...
0 0 1 0;...
0 0 0 1];
MAT = PROJXY;
end
newpoint = MAT*oldpoint;
end

Result
Tutorial:
1. 2D Transformation (Translation, Shearing & Rotation)
Result
Tutorial:
2. 3D Transformation (Translation, Shearing & Rotation)
Results
Tutorial:
3. Conic Sections and Cubic Splines
Results
Tutorial:
4. Bezier Curves and B Splines Surfaces of Revolution
Results
Tutorial:
5. Surfaces of Revolution
Results
Tutorial:
6. Ruled and Sweep Surfaces
Results
Tutorial:
7. Bilinear and Coon’s Surfaces
Results
Tutorial:
8. Consider the bar as shown in the figure below.
Determine the nodal displacements and support
Results
Assignment 1

Assignment 2
Assignment 3

Assignment 4
Assignment 5
Assignment 6

Assignment 7
Assignment 8

You might also like