Sunday 16 August 2015

Three link robotic arm drawing a circle (simulation of human shoulder and elbow joint)

Sample Output : 
Robotics, C program for simulation of robotic arm drawing a circle

Robotics, C program for simulation of robotic arm drawing a circle

Robotics, C program for simulation of robotic arm drawing a circle

#include<graphics.h>
#include<math.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>

void main(){
 int gd=DETECT, gm;
 int k=1;
 float xc,c1,c2,x1,y1,y2,x2,x3,y3,xr,yr;
 initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
 x1=120;y1=150;
 x2=220;y2=150;
 c1=195;c2=150;


setcolor(LIGHTBLUE);
line(xc,50,xc,150);
//putpixel(x1,y1,GREEN);

setcolor(YELLOW);
 line(xc,150,x1,y1);
 setcolor(CYAN);
line(x1,y1,x2,y2);
 setcolor(WHITE);

line(x2-2,y2-2,x2,y2);
line(x2-2,y2-2,x2-2,y2+2);
line(x2-2,y2+2,x2,y2);

outtextxy(10,300,"Press any key to start drawing circle");
getch();

while(k<360 ){
k+=1;
xr= (x2-c1)*cos(M_PI/180) - (y2-c2)*sin(M_PI/180) + c1;
yr= (x2-c1)*sin(M_PI/180) + (y2-c2)*cos(M_PI/180) + c2;
x2=xr;
y2=yr;

y1= y2 + sqrt( 100*100 - (x1-x2)*(x1-x2));
xc=x1-sqrt(100*100-(150-y1)*(150-y1));

delay(20);
cleardevice();
setcolor(LIGHTBLUE);
line(xc,50,xc,150);
setcolor(YELLOW);
 line(xc,150,x1,y1);
 setcolor(CYAN);
line(x1,y1,x2,y2);
setcolor(WHITE);
line(x2-2,y2-2,x2,y2);
line(x2-2,y2-2,x2-2,y2+2);
line(x2-2,y2+2,x2,y2);
setcolor(GREEN);
 arc(c1,c2,360-k,360,25);

}

    setfillstyle(SOLID_FILL,BLACK);
    floodfill(c1+1,c2-1,GREEN);

 getch();



}

No comments:

Post a Comment