2017-02-27 125 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); 

我希望這給你足夠的信息來完成其餘的。