Hi, i really don't know what to do guys can you help me with this code for my matrix program? this program is not yet finished and i am stuck with this problem

#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    int rotx, roty, rotz, n, ac1, ac2, ac3, ac4, atransx, atransy, atransz;
    double axx1, ayx1, azx1, axy1, ayy1, azy1, axz1, ayz1, azz1;
    int transx=0;
    int transy=0;
    int transz=0;
    int c1=0;
    int c2=0;
    int c3=0;
    int c4=1;
    int counter;
    int count=0;
    char command;
    Start:
    float xx1 = 0;
    float yx1 = 0;
    float zx1 = 0;
    float xy1 = 0;
    float yy1 = 0;
    float zy1 = 0;
    float xz1 = 0;
    float yz1 = 0;
    float zz1 = 0;

    cout<<"Choose a command (Maximum of 3 Operations):"<<endl;
    cout<<"[1] Rotate X"<<endl<<"[2] Rotate Y"<<endl<<"[3] Rotate Z"<<endl<<"[4] Add Transformation"<<endl<<"[6] Calculate"<<endl<<"[7] Quit"<<endl<<"Choice: ";
    cin>>n;

    switch (n){
    case 1:
    cout <<"Rotate X at angle: "<<endl;
        cin >> rotx;
        xx1 = sin (rotx*3.14/180);
        yx1 = cos (rotx*3.14/180);
        zx1 = cos (rotx*3.14/180);
        xy1 = cos (rotx*3.14/180);
        yy1 = cos (rotx*3.14/180);
        zy1 = sin (rotx*3.14/180);
        xz1 = cos (rotx*3.14/180);
        yz1 = -sin (rotx*3.14/180);
        zz1 = cos (rotx*3.14/180);
        count=count+1;
        cout<<"Angle included"<<endl<<endl;
        goto Input;
    break;


    case 2:
    cout<<"Rotate Y at angle: "<<endl;
        cin >> roty;
        xx1 = cos (roty*3.14/180);
        yx1 = cos (roty*3.14/180);
        zx1 = -sin (roty*3.14/180);
        xy1 = cos (roty*3.14/180);
        yy1 = sin (roty*3.14/180);
        zy1 = cos (roty*3.14/180);
        xz1 = sin (roty*3.14/180);
        yz1 = cos (roty*3.14/180);
        zz1 = cos (roty*3.14/180);
        count++;
        cout<<"Angle included"<<endl<<endl;
        goto Input;
    break;

    case 3:
    cout <<"Rotate Z at angle: "<<endl;
        cin >> rotz;
        xx1 = cos (rotz*3.14/180);
        yx1 = sin (rotz*3.14/180);
        zx1 = cos (rotz*3.14/180);
        xy1 = -sin (rotz*3.14/180);
        yy1 = cos (rotz*3.14/180);
        zy1 = cos (rotz*3.14/180);
        xz1 = cos (rotz*3.14/180);
        yz1 = cos (rotz*3.14/180);
        zz1 = sin (rotz*3.14/180);
        count++;
        cout<<"Angle included"<<endl<<endl;
        goto Input;
    break;
    } //end of cases

    Input:
    if (count==1)
    {
        axx1=xx1;
        ayx1=yx1;
        azx1=zx1;
        ac1=c1;
        axy1=xy1;
        ayy1=yy1;
        azy1=zy1;
        ac2=c2;
        axz1=xz1;
        ayz1=yz1;
        azz1=zz1;
        ac3=c3;
        atransx=transx;
        atransy=transy;
        atransz=transz;
        ac4=c4;

        cout<<"Your Translation is:"<<endl<<endl;
        cout<<" "<<axx1<<" "<<axy1<<" "<<axz1<<" "<<atransx<<" "<<endl;
        cout<<" "<<ayx1<<" "<<ayy1<<" "<<ayz1<<" "<<atransy<<" "<<endl;
        cout<<" "<<azx1<<" "<<azy1<<" "<<azz1<<" "<<atransz<<" "<<endl;
        cout<<" "<<ac1<<" "<<ac2<<" "<<ac3<<" "<<ac4<<" "<<endl<<endl<<endl;
        goto Start;
    }
    else

    return 0;
}

output:
1 0.000796327 0.000796327 0
0.000796327 0.000796327 -1 0
0.000796327 1 0.000796327 0
0 0 0 1

output should be:
1 0 0 0
0 0 -1 0
0 1 0 0
0 0 0 1

any idea how can i have this??? thanks a lot

Edited 6 Years Ago by lloydi12345: n/a

Welcome to floating point. :) You'll find that small errors here and there can propagate very quickly. First try a much better approximation for pi and see how it changes things. It may buy you a little bit. Also, going from floats to doubles probably doesn't buy you much and just takes an extra step.

Edited 6 Years Ago by jonsca: n/a

Part of this program doesn't make much sense to me. First, you have:

double axx1;
float xx1 = 0;

Then you do some calculations and then:

axx1=xx1;

Converting from a float to a double doesn't do anything at all for you. If you want more precision then why don't you just use doubles all the way through the program? I believe that the math functions that you use (sin, cos, tan) can take floats, doubles, and long doubles so you'll be fine and you'll get an answer that's closer to what you're looking for due to the extra precision that you'll get.

You may also consider formatting the output to limit the number of digits after the decimal.

Edited 6 Years Ago by necrolin: n/a

Welcome to floating point. :) You'll find that small errors here and there can propagate very quickly. First try a much better approximation for pi and see how it changes things. It may buy you a little bit. Also, going from floats to doubles probably doesn't buy you much and just takes an extra step.

Thank you, now i have declared this on above
const double PI = 4.0*atan(1.0);

and changed my floats to doubles

Part of this program doesn't make much sense to me. First, you have:

double axx1;
float xx1 = 0;

Then you do some calculations and then:

axx1=xx1;

Converting from a float to a double doesn't do anything at all for you. If you want more precision then why don't you just use doubles all the way through the program? I believe that the math functions that you use (sin, cos, tan) can take floats, doubles, and long doubles so you'll be fine and you'll get an answer that's closer to what you're looking for due to the extra precision that you'll get.

You may also consider formatting the output to limit the number of digits after the decimal.

Thank you for the reply, i now edited the program.. i have axx1=xx1 because i'll be using 3 matrices, and the first matrix is for axx1 axy1 axz1 and so on, while the 2nd is bxx1 bxy1 and so on, and the last is cxx1 cxy1 cxz1 and so on and i'l be multiplying them at the end.. i am not yet finished with the program because im stuck with the 1 digit thing

0.000796327 is effectively 0. Look up the iomanip header and output exactly the number of decimals you need.

This article has been dead for over six months. Start a new discussion instead.