Forward Kinematics Problem (Rotate Robot Arm According To Input Angle)


#include<GRAPHICS.h> #include<stdio.h> #include<math.h> double radian(int val) { return (M_PI*val)/180; } void rotate(int x_c,int y_c,int a,int b,int *x_p,int *y_p,int degree) { double rad=radian(degree); *x_p=((a-x_c)*cos(rad))-((b-y_c)*sin(rad))+x_c; *y_p=((a-x_c)*sin(rad))+((b-y_c)*cos(rad))+y_c; } int rotate_motor_logically(int motor_no,int angle,int* lx,int* ly) { int a,b; if(motor_no==1) { rotate(lx[0],ly[0],lx[1],ly[1],&a,&b,angle); lx[1]=a,ly[1]=b; rotate(lx[0],ly[0],lx[2],ly[2],&a,&b,angle); lx[2]=a,ly[2]=b; } if(motor_no==2) { rotate(lx[1],ly[1],lx[2],ly[2],&a,&b,angle); lx[2]=a; ly[2]=b; } return 1; } int main() { int lx[3],ly[3],motor_no,angle; /* request auto detection */ int gdriver = DETECT, gmode; /* initialize graphics mode */ initgraph(&gdriver, &gmode, "C:\\TurboC3\\BGI"); lx[0]=getmaxx()/2; ly[0]=getmaxy()/2; lx[1]=lx[0]+110; ly[1]=ly[0]; lx[2]=lx[1]; ly[2]=ly[1]-100; setcolor(BLUE); line(lx[0],ly[0],lx[1],ly[1]); setcolor(RED); line(lx[1],ly[1],lx[2],ly[2]); printf("Enter motor no :\n"); scanf("%d",&motor_no); printf("Enter angle :\n"); scanf("%d",&angle); clrscr(); rotate_motor_logically(motor_no,angle,lx,ly); setcolor(BLUE); line(lx[0],ly[0],lx[1],ly[1]); setcolor(RED); line(lx[1],ly[1],lx[2],ly[2]); getch(); return 0; }

Input :



Output :



No comments: