(我已经检查了this,但据我所知,由于平面角度与我的不同,它与我的问题无关。)
我正在用C ++编写一个小软件,用于我目前在大学舞台上做的一个小项目。
我正在编写一个机器人手臂,用3D模型将一块聚苯乙烯塑造成一个形状。到现在为止,我已经在手臂上找到了一个“翻译”,我需要做的就是在太空中为他提供位置。格式必须是
< x , y , z , e1 , e2 , e3 , > TRUE
以x,y和z为空间坐标,e1,e2和e2为欧拉角。 (最后为TRUE告诉手臂这不是最后的动作)。
我有一个基本的草稿(真的非常基本)从每个三角形中捕获点并进行翻译,但我没有办法获得欧拉角。 .stl格式为每个三角形提供了一个向量,但我无法将其转换为3个欧拉角。使用acos()我可以从向量的3轴获得3个角度,但之后我的想法最终变干。
机器人手臂移动“zyz”,因此e1在z附近,e2在y周围,e3在z周围。
顺便说一下,这是代码
#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");
}
感谢您的时间。我真的迷失在这里。