|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
C++ Program assistance
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
New to Overclock.net
|
I have a program that I need assistance on:
here is the code: // PUMA.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include<iostream> #include<math.h> #include <conio.h>//prototype for getch() function using namespace std; double ** trans_matrix(int m); double ** Memoryallocator(double ** ptr,int rows, int cols); void initializer(double ** ptr,int rows, int cols); void Memorydallocator(double ** ptr,int rows, int cols); double ** transform(double alpha_i_1[6], double a_i_1[6], double d_i[6], double theta_i[6], int i); double ** mul(double ** m1, double ** m2, int r, int c); void print(double ** ptr, int rows,int cols); int _tmain(int argc, _TCHAR* argv[]) { int m=6; char ttt = '0'; double ** t=trans_matrix(m); print(t,4,4); double y=-1.0*t[2][0]; double x=sqrt( (t[0][0] * t[0][0]) + (t[1][0]) * t[1][0]); double beta=atan2(y,x); // calculates the angle beta i.e. orientation along Y-axis y=t[1][0]/cos(beta); x=t[0][0]/cos(beta); double alpha=atan2(y,x); // calculates the angle alpha i.e. orientation along X-axis y=t[2][1]/cos(beta); x=t[2][2]/cos(beta); double gamma=atan2(y,x);// calculates the angle gamma i.e. orientation along Z-axis beta=7.0*beta*180/22.0; // conversion from radians to degrees alpha=7.0*alpha*180/22.0; gamma=7.0*gamma*180/22.0; cout<<endl<<"X-Fixed Orientation: "<<alpha<<endl; cout<<endl<<"Y-Fixed Orientation: "<<beta<<endl; cout<<endl<<"Z-Fixed Orientation: "<<gamma<<endl; cout<<endl<<"Position Vector: "<<endl; cout<<endl<<"X "<<t[0][3]<<endl; cout<<endl<<"Y "<<t[1][3]<<endl; cout<<endl<<"Z "<<t[2][3]<<endl; cout<<endl<<"Press Any Key to Close Program"<<endl; ttt=getch(); return 0; } double ** transform(double alpha_i_1[6], double a_i_1[6], double d_i[6], double theta_i[6], int i) { alpha_i_1[0]=0.0;alpha_i_1[1]=-90.0;alpha_i_1[2]=0.0; // given alpha angles alpha_i_1[3]=-90.0;alpha_i_1[4]=90.0;alpha_i_1[5]=-90.0; a_i_1[0]=0.0;a_i_1[1]=0.0;a_i_1[2]=17.0; // given a distnaces a_i_1[3]=0.8;a_i_1[4]=0.0;a_i_1[5]=0.0; d_i[0]=0.0;d_i[1]=0.0;d_i[2]=4.9; // given d distances d_i[3]=17.0;d_i[5]=0.0;d_i[5]=0.0; theta_i[0]=60.0;theta_i[1]=45.0;theta_i[2]=25.0; // given thetas theta_i[3]=15.0;theta_i[4]=-10.0;theta_i[5]=-30.0; double ** trans_i_1_i=NULL; trans_i_1_i = Memoryallocator(trans_i_1_i,4,4); /*for(int k = 0; k<6 ; k++) { cout<<endl<<theta_i[k]; theta_i[k]=(3.14157*theta_i[k]/180.0); cout<<endl<<theta_i[k]; alpha_i_1[k]=3.14157*alpha_i_1[k]/180.0; }*/ if(i==1) // calculates the transformation from joint1 to joint0 { i--; cout<<endl<<"Transform from Joint 1 to Joint 0"<<endl; theta_i[i]=theta_i[i]*3.14157/180.0; trans_i_1_i[0][0]=cos(theta_i[i]); trans_i_1_i[0][1]=-1.0 * sin(theta_i[i]); trans_i_1_i[0][2]=0.0; trans_i_1_i[0][3]=0.0; trans_i_1_i[1][0]=sin(theta_i[i]); trans_i_1_i[1][1]=cos(theta_i[i]); trans_i_1_i[1][2]=0.0; trans_i_1_i[1][3]=0.0; trans_i_1_i[2][0]=0.0; trans_i_1_i[2][1]=0.0; trans_i_1_i[2][2]=1.0; trans_i_1_i[2][3]=0.0; trans_i_1_i[3][0]=0.0; trans_i_1_i[3][1]=0.0; trans_i_1_i[3][2]=0.0; trans_i_1_i[3][3]=1.0; //return trans_i_1_i[0]=[cos(theta_i[i]) -sin(theta_i(i)) 0 0; sin(theta_i(i)) cos(theta_i(i)) 0 0; 0 0 1 0; 0 0 0 1]; } if( i==2)// calculates the transformation from joint1 to joint0 { i--; cout<<endl<<"Transform from Joint 2 to Joint 1"<<endl; theta_i[i]=theta_i[i]*3.14157/180.0; trans_i_1_i[0][0]=cos(theta_i[i]); trans_i_1_i[0][1]=-1.0 * sin(theta_i[i]); trans_i_1_i[0][2]=0.0; trans_i_1_i[0][3]=0.0; trans_i_1_i[1][0]=0.0; trans_i_1_i[1][1]=0.0; trans_i_1_i[1][2]=1.0; trans_i_1_i[1][3]=0.0; trans_i_1_i[2][0]=-1.0 * sin(theta_i[i]); trans_i_1_i[2][1]=-1.0 * cos(theta_i[i]); trans_i_1_i[2][2]=0.0; trans_i_1_i[2][3]=0.0; trans_i_1_i[3][0]=0.0; trans_i_1_i[3][1]=0.0; trans_i_1_i[3][2]=0.0; trans_i_1_i[3][3]=1.0; } if(i==3)// calculates the transformation from joint1 to joint0 { i--; cout<<endl<<"Transform from Joint 3 to Joint 2"<<endl; theta_i[i]=theta_i[i]*3.14157/180.0; trans_i_1_i[0][0]=cos(theta_i[i]); trans_i_1_i[0][1]=-1.0 * sin(theta_i[i]); trans_i_1_i[0][2]=0.0; trans_i_1_i[0][3]=a_i_1[i-1]; trans_i_1_i[1][0]=sin(theta_i[i]); trans_i_1_i[1][1]=cos(theta_i[i]); trans_i_1_i[1][2]=0.0; trans_i_1_i[1][3]=0.0; trans_i_1_i[2][0]=0.0; trans_i_1_i[2][1]=0.0; trans_i_1_i[2][2]=1.0; trans_i_1_i[2][3]=d_i[i]; trans_i_1_i[3][0]=0.0; trans_i_1_i[3][1]=0.0; trans_i_1_i[3][2]=0.0; trans_i_1_i[3][3]=1.0; } if(i==4)// calculates the transformation from joint1 to joint0 { i--; cout<<endl<<"Transform from Joint 4 to Joint 3"<<endl; theta_i[i]=theta_i[i]*3.14157/180.0; trans_i_1_i[0][0]=cos(theta_i[i]); trans_i_1_i[0][1]=-1.0 * sin(theta_i[i]); trans_i_1_i[0][2]=0.0; trans_i_1_i[0][3]=a_i_1[i-1]; trans_i_1_i[1][0]=0.0; trans_i_1_i[1][1]=0.0; trans_i_1_i[1][2]=1.0; trans_i_1_i[1][3]=d_i[i]; trans_i_1_i[2][0]=-1.0 * sin(theta_i[i]); trans_i_1_i[2][1]=-1.0 * cos(theta_i[i]); trans_i_1_i[2][2]=0.0; trans_i_1_i[2][3]=0.0; trans_i_1_i[3][0]=0.0; trans_i_1_i[3][1]=0.0; trans_i_1_i[3][2]=0.0; trans_i_1_i[3][3]=1.0; } if(i==5)// calculates the transformation from joint1 to joint0 { i--; cout<<endl<<"Transform from Joint 5 to Joint 4"<<endl; theta_i[i]=theta_i[i]*3.14157/180.0; trans_i_1_i[0][0]=cos(theta_i[i]); trans_i_1_i[0][1]=-1.0 * sin(theta_i[i]); trans_i_1_i[0][2]=0.0; trans_i_1_i[0][3]=0.0; trans_i_1_i[1][0]=0.0; trans_i_1_i[1][1]=0.0; trans_i_1_i[1][2]=-1.0; trans_i_1_i[1][3]=0.0; trans_i_1_i[2][0]=sin(theta_i[i]); trans_i_1_i[2][1]=cos(theta_i[i]); trans_i_1_i[2][2]=0.0; trans_i_1_i[2][3]=0.0; trans_i_1_i[3][0]=0.0; trans_i_1_i[3][1]=0.0; trans_i_1_i[3][2]=0.0; trans_i_1_i[3][3]=1.0; } if(i==6)// calculates the transformation from joint1 to joint0 { i--; cout<<endl<<"Transform from Joint 6 to Joint 5"<<endl; theta_i[i]=theta_i[i]*3.14157/180.0; trans_i_1_i[0][0]=cos(theta_i[i]); trans_i_1_i[0][1]=-1.0 * sin(theta_i[i]); trans_i_1_i[0][2]=0.0;; trans_i_1_i[0][3]=0.0; trans_i_1_i[1][0]=0.0; trans_i_1_i[1][1]=0.0; trans_i_1_i[1][2]=1.0; trans_i_1_i[1][3]=0.0; trans_i_1_i[2][0]=-1.0 * sin(theta_i[i]); trans_i_1_i[2][1]=-1.0 * cos(theta_i[i]); trans_i_1_i[2][2]=0.0; trans_i_1_i[2][3]=0.0; trans_i_1_i[3][0]=0.0; trans_i_1_i[3][1]=0.0; trans_i_1_i[3][2]=0.0; trans_i_1_i[3][3]=1.0; } //print(trans_i_1_i,4,4); return trans_i_1_i; } double ** trans_matrix(int m)//takes a number 'm' and returns a 4 x 4 matrix from that joint m to joint 0 { double b1[6]; double b2[6]; double b3[6]; double b4[6]; double ** t_1; double ** t_2; double ** t_3; double ** t_4; double ** t_5; double ** t_6; if(m==1) { cout<<endl<<"Transformation Matrix from Joint 1 to Joint 0"<<endl; return transform(b1,b2,b3,b4,1); } if(m==2) { t_2=transform(b1,b2,b3,b4,2); t_1=transform(b1,b2,b3,b4,1); cout<<endl<<"Transformation Matrix from Joint 2 to Joint 0 "; return mul(t_1,t_2,4,4); } if(m==3) { t_3=transform(b1,b2,b3,b4,3); t_2=transform(b1,b2,b3,b4,2); t_1=transform(b1,b2,b3,b4,1); t_2=mul(t_2,t_3,4,4); cout<<endl<<"Transformation Matrix from Joint 3 to Joint 0 "; return mul(t_1,t_2,4,4); } if(m==4) { t_4=transform(b1,b2,b3,b4,4); t_3=transform(b1,b2,b3,b4,3); t_2=transform(b1,b2,b3,b4,2); t_1=transform(b1,b2,b3,b4,1); t_3=mul(t_3,t_4,4,4); t_2=mul(t_2,t_3,4,4); cout<<endl<<"Transformation Matrix from Joint 4 to Joint 0 "; return mul(t_1,t_2,4,4); } if(m==5) { t_5=transform(b1,b2,b3,b4,5); t_4=transform(b1,b2,b3,b4,4); t_3=transform(b1,b2,b3,b4,3); t_2=transform(b1,b2,b3,b4,2); t_1=transform(b1,b2,b3,b4,1); t_4=mul(t_4,t_5,4,4); t_3=mul(t_3,t_4,4,4); t_2=mul(t_2,t_3,4,4); cout<<endl<<"Transformation Matrix from Joint 5 to Joint 0"; return mul(t_1,t_2,4,4); } if(m==6) { t_6=transform(b1,b2,b3,b4,6); t_5=transform(b1,b2,b3,b4,5); t_4=transform(b1,b2,b3,b4,4); t_3=transform(b1,b2,b3,b4,3); t_2=transform(b1,b2,b3,b4,2); t_1=transform(b1,b2,b3,b4,1); t_5=mul(t_5,t_6,4,4); t_4=mul(t_4,t_5,4,4); t_3=mul(t_3,t_4,4,4); t_2=mul(t_2,t_3,4,4); print(t_5,4,4); print(t_2,4,4); print(t_3,4,4); print(t_4,4,4); cout<<endl<<"Transformation Matrix from Joint 6 to Joint 0 "; return mul(t_1,t_2,4,4); } } double ** mul(double ** m1, double ** m2, int r, int c) // takes two matrices; their row & col sizes and return the multiplication result { double ** to_return=NULL; to_return = Memoryallocator(to_return,4,4); int counter=0; double sum=0.0; while(counter<r) { for(int i=0;i<c;i++) { sum=0.0; for(int j=0;j<c;j++) sum+=*(*(m1+counter)+j) * *(*(m2+j)+i); *(*(to_return+counter)+i)=sum; } counter++; } return to_return; } /*{ double ** to_return=NULL; to_return = Memoryallocator(to_return,4,4); for(int i=0; i<r; i++) { for(int j=0; j<c; j++) { to_return[i][j] =0.0; for(int k=0; k<c; k++) to_return[i][j] += m1[i][k]*m2[k][i]; } } return to_return; }*/ double ** Memoryallocator(double ** ptr,int rows, int cols) { ptr= new double * [rows]; for(int counter=0;counter<rows;counter++) ptr[counter] = new double [cols]; return ptr; } void initializer(double ** ptr,int rows,int cols) { for(int counter=0; counter<rows; counter++) for(int counter1=0; counter1<cols; counter1++) ptr[counter][counter1] = 0.0; } void Memorydallocator(double ** ptr,int rows, int cols) { for(int counter=0;counter<rows;counter++) delete [] ptr[counter]; delete [] ptr; ptr=0; } //temporary function that prints array used for Debugging void print(double ** ptr,int rows, int cols) { /*int locx, locy; int locx1 = rows, locy1 = cols; cout<<endl; for(locx=0; locx < locx1; locx++) { for(locy=0; locy<locy1; locy++) cout << ptr[locx][locy]<< '\t'; cout << endl; } */ } these are the erros i am getting: PUMA.cpp:3:20: stdafx.h: No such file or directory PUMA.cpp:6:51: conio.h: No such file or directory PUMA.cpp:15: error: `_TCHAR' has not been declared PUMA.cpp:16: error: ISO C++ forbids declaration of `argv' with no type H:\My Documents\PUMA.cpp: In function `int _tmain(int, int**)': PUMA.cpp:46: error: `getch' undeclared (first use this function) PUMA.cpp:46: error: (Each undeclared identifier is reported only once for each function it appears in.) |
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
4.0ghz
![]() |
Looks like you have tried to compile a program written for Windows on another platform, such as Mac or Linux, specifically using gcc. It would probably take about five minutes to port the program, or you can install the Microsoft compiler, which will take about an hour.
__________________
The Ice Stone has melted! I did error10's Windows Challenge and I now am an MCSE: Minesweeper Consultant and Solitaire Expert! ![]()
|
|||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||
|
Commodore 64
![]() |
cout<<"Do you like poop?"<<endl;
cin>>answer; cout<<"\n\n"<<"YOU LIKE POOP!"<<endl; .......... "i'm a n00b... way above MY head.".
__________________
Quote:
-S. G. Tallentyre "Thank You Bacchus451 for pointing out my misquote."
|
|||||||||||||
|
|
|
|
|
#4 (permalink) | ||||||||||||||
|
Security Sleuth
![]() |
Taking others work is no fun.
__________________
Quote:
Proud Member of the Linux Gaming CommunityI am your friend.
|
||||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|