Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 02-10-09   #1 (permalink)
New to Overclock.net
 
Join Date: Feb 2009
Posts: 1

Rep: 0 lilmoose4 Unknown
Unique Rep: 0
Trader Rating: 0
Default C++ Program assistance

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.)
lilmoose4 is offline   Reply With Quote
Old 02-10-09   #2 (permalink)
4.0ghz
 
error10's Avatar
 
intel nvidia

Join Date: Sep 2008
Location: Manchester, New Hampshire
Posts: 9,737
Blog Entries: 4

Rep: 1167 error10 is a starerror10 is a starerror10 is a starerror10 is a starerror10 is a starerror10 is a starerror10 is a starerror10 is a starerror10 is a star
Unique Rep: 708
Hardware Reviews: 1
Trader Rating: 45
Default

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.

System: Underground
CPU
Core i7 920
Motherboard
ASUS P6T6 WS Revolution
Memory
3x2GB Corsair Dominator DDR3-1600
Graphics Card
EVGA 9800 GT SC 512MB
Hard Drive
4x MBA3147RC RAID5
Sound Card
Intel ICH10 HD Audio / ADI Codec
Power Supply
BFG ES-800
Case
Thermaltake Armor VA8003BWS
CPU cooling
TRUE Lapped + Scythe Slip Stream 1900
GPU cooling
Stock
OS
Fedora 10 x86_64
Monitor
HP w19b
3 Million+ Folding at Home points
error10 is offline Overclocked Account error10's Gallery   Reply With Quote
Old 02-10-09   #3 (permalink)
Commodore 64
 
Gillos's Avatar
 
intel nvidia

Join Date: May 2007
Posts: 1,127

Rep: 104 Gillos is acknowledged by manyGillos is acknowledged by many
Unique Rep: 91
Trader Rating: 0
Default

cout<<"Do you like poop?"<<endl;
cin>>answer;

cout<<"\n\n"<<"YOU LIKE POOP!"<<endl;

..........

"i'm a n00b... way above MY head."

.
__________________
Quote:
I disagree with what you say, but I will defend to the death your right to say it.
-S. G. Tallentyre

"Thank You Bacchus451 for pointing out my misquote."

System: The Newest Gillos Computer
CPU
Core 2 Quad Q6600 @3.6GHz
Motherboard
Asus P5N-D SLI
Memory
6GB - OCZ Platinum XTC
Graphics Card
9800GTX+ SLI
Hard Drive
Seagate Barracuda 250GB
Sound Card
X-Fi Xtreme
Power Supply
Antec Quatro 850W
Case
Antec Nine Hundred
CPU cooling
Arctic Freezer Pro 2
GPU cooling
Zalman VF1000
OS
Windows Vista 64bit
Gillos is offline   Reply With Quote
Old 02-12-09   #4 (permalink)
Security Sleuth
 
Pooping^fish's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: egypt
Posts: 1,267

Rep: 67 Pooping^fish is acknowledged by some
Unique Rep: 62
Trader Rating: 3
Default

Taking others work is no fun.
__________________
Quote:
"O, hai! Want som pRon? Dwnlod ths kodk frst. Its teh bst pRonz ever, we prmis." -GibbyGano
Proud Member of the Linux Gaming Community
I am your friend.

System: ragequit
CPU
Q9550 4ghz @ 1.25v
Motherboard
Asus Max 2 formula
Memory
OCZ LV blade 1:1 950mhz
Graphics Card
8800gtx 610/1ghz
Hard Drive
7200.10 250gb
Sound Card
X-FI Extreme Music
Power Supply
750w Toughpower
Case
Lian li pc-65
CPU cooling
TRUE
GPU cooling
stock
OS
leetlinucks
Monitor
24" Westy
Pooping^fish is offline   Reply With Quote
Old 02-12-09   #5 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 236

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

Someone actually got paid for writing that turd?
__________________
Rich
Custom Wooden Case Builder
Overclock.net Mod of the Month
Spotswood is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 08:13 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.18010 seconds with 8 queries