2017-02-27 128 views
0

当前正在为我的计算类在C++中的一个项目挣扎。被要求在三维空间中相对于三轴旋转三个角度。围绕某个轴的点的旋转

感觉像IM还挺近的有需要的只是努力把它们放在一起的所有部件,讲义是一个有点模糊的矩阵相乘:(。任何帮助表示赞赏。

#include "stdafx.h" 
#include <iostream> 

using namespace std; 
int main() 
{ 
std::cout << "Enter a number for x"; 
int x; 
std::cin >> x; 
std::cout << "Enter a number for y"; 
int y; 
std::cin >> y; 
std::cout << "Enter a number for z"; 
int z; 
std::cin >> z; 
std::cout << "Enter value for Theta"; 
int theta; 
std::cin >> theta; 
std::cout << "Enter value for Beta"; 
int beta; 
std::cin >> beta; 
std::cout << "Enter value for Gamma"; 
int gamma; 
std::cin >> gamma; 


//function allows the insertion of xyz and the three angles 


{void RTheta(const double& theta, double array[3][3]); 

int array = 
{ 
    {cos(theta), sin(theta), 0},      //the matrice for theta values 
    {sin(theta), cos(theta), 0}, 
    {0,0,1} 
}; 
std::cout << RTheta;         //outputs value for theta 

} 

{ 
    void RBeta(const double& beta, double array[3][3]); 

    int array = 
    { 
     {cos(beta), 0, -sin(beta)},       //the matrice for beta values 
     {0, 1, 0},           //outputs values for beta 
     {sin(beta), 0, cos(beta)} 
    }; 
    std::cout << RBeta; 
} 
{ 
    void RGamma(const double& gamma, double array[3][3]); 

    int array = 
    { 
     {1,0,0},           //the matrice for gamma 
     {0,cos(gamma), sin(gamma)},       //outputs values for gamma 
     {0, -sin(gamma), cos(gamma)} 
    }; 
    std::cout << RGamma; 
} 
return 0; 
} 

如果这个问题帮助:i.imgur.com/eN5RqEe.png

+1

看起来你正试图在函数内定义函数。 C++不允许这样做。在'main'之外定义这些函数。您可能会发现将它们放在'main'上方更容易,因为您不需要前向声明。我给你的最佳建议是[破解一本好书并阅读正确的语法](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)。 – user4581301

+0

看着你的文字,它说Q21'下一个练习可以包括myArray.h'。你不包括它。另外,前面的问题讨论了开发*函数*,而不是*类*;如果一个类有一个成员'void RTheta(const double&theta,double array [3] [3])',那么类将会更有意义,因为该签名没有'(x,y,z)'坐标。 –

+0

@ user4581301感谢您的答复,即时通讯新的C + +一直在努力。只是为了澄清你的意思是移动所有关于在主函数上方输入x,y,theta等的位?第二部分又是如何看待的?我正在努力弄清楚如何将所有东西捆绑在一起。 –

回答

1

你需要开始从一个角度抽象一点上有所考虑,而不是迷失在细节你需要的抽象PointTransform并创建与这些抽象的工作职能。

如果使用2D点工作,使用方法:

struct Point 
{ 
    double x; 
    double y; 
}; 

如果需要使用3D点,使用的工作:

struct Point 
{ 
    double x; 
    double y; 
    double z; 
}; 

如果你有兴趣只在旋转变换,可以使用以下为2D转换:

struct Transform 
{ 
    double matrix[2][2]; 
}; 

对于3D转换,你可以使用:

struct Transform 
{ 
    double matrix[3][3]; 
}; 

然后添加函数来构造点,转换并对它们执行操作。例如。

Point constructPoint(double x, double y); 

Transfrom constructIdentityTransform(); 
Transfrom constructRotateAroundXTransform(double xrot); 
Transfrom constructRotateAroundYTransform(double yrot); 
Transfrom constructRotateAroundZTransform(double yrot); 

Transform operator*(Transform const& lhs, Transform const& rhs); 

Point operator*(Transform const& trans, Point const& p); 

我希望这给你足够的信息来完成其余的。