1

(I already checked this, but as far as I understood, it does not relate to my problem due to the fact that planes angles are different from mine.)

I'm writing a little piece of software in C++ for a little project I'm currently doing at a Stage in university.

I'm programming a Robotic Arm to sculpt a piece of polystyrene into a shape from a 3D model. By now, I already got an "interpreter" on the arm, all I need to do is feed him with positions in space. The format must be

< x , y , z , e1 , e2 , e3 , > TRUE

With x, y and z as spatial coordinates and e1, e2 and e2 as euler angles. (TRUE at the end just tells the arm that this is not the last movement).

I have a basic draft (really really basic) that catches the points from each triangle and translates it, but I lack a way to get the euler angles. .stl format provides a vector for each triangle, but I just can't convert that into 3 euler angles. With acos() I could get the 3 angles from the 3 axis of the vector, but after that my ideas end up dry.

The robot arm moves "zyz", so e1 is around z, e2 around y and e3 around z again.

This is the code, by the way

#include <fstream>
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[])
{
    int defin = 0;
    if (argv[1] == 0)
    {
        argv[1] = "./input.stl";
        defin = 1;
    }
    ifstream infile(/*argv[1]*/"./input.stl");
    ofstream outfile("./sculpture.scl");
    string inln = "";
    string outln = "";
    bool stop = 1;
    string bnum = "";
    string x = "";
    string y = "";
    string z = "";
    string e1 = "0";
    string e2 = "0";
    string e3 = "0";
    int c = 0;

    system("pause");
    cout << "|| Starting translation...\n";

        /*Here comes the stuff to get the name of the thingo. By now I'll just leave a note.*/
    getline(infile, inln);
    while (stop)
    {
        getline(infile, inln);
        if (inln[2] == 'f')
        {
            cout << "angles incoming\n";
            inln = inln + ';';
            /*Here I get the angles. By now I'll just leave a note.*/
        }
        else if (inln[6] == 'v')
        {
            cout << "coordinates incoming\n";
            inln = inln + ';';
            while (inln[c] != 'x')
            {
                c++;
                cout << "reaching x\n";
            }
            c++;
            c++;
            while (inln[c] != ' ')
            {
                bnum = bnum + inln[c];
                c++;
                cout << "x\n";
            }
            c++;
            x = bnum;
            bnum = "";
            while (inln[c] != ' ')
            {
                bnum = bnum + inln[c];
                c++;
                cout << "y\n";
            }
            c++;
            y = bnum;
            bnum = "";
            while (inln[c] != ';')
            {
                bnum = bnum + inln[c];
                c++;
                cout << "z\n";
            }
            c++;
            z = bnum;
            bnum = "";

            outln = "<" + x + "," + y + "," + z + ","+ e1 + "," + e2 + "," + e3 + ",>TRUE";
            outfile << outln << endl;
            c = 0;
        }
        else if (inln[5] == 'u')
        {
            cout << "outer loop\n";
            /*Nada here*/
        }
        else if (inln[4] == 'e')
        {
            cout << "endloop\n";
            /*End the Triangle, switch the angles!*/
        }
        else if (inln[2] == 'e')
        {
            cout << "endfacet\n";
            /*Same as above*/
        }
        else if (inln[0] == 'e')
        {
            cout << "Reached the end\n";
            stop = 0;
        }
        else
        {
            cout << "Dafuq just happened lel\n";
            system("pause");
            return 1;
        }
    }
    outln = "<0,0,0,0,0,0,>FALSE";
    outfile << outln;
    system("pause");
}

Thanks for your time. I'm really really lost here.

Community
  • 1
  • 1
Alunduyn
  • 11
  • 2

0 Answers0