私はC++で同次変換を使用しようとしていますが、行列乗算を使用することはできません。コードで何か間違っているのですか?Cantは行列乗算を正しく処理しています
私はそれを手作業で行うことを確認したが、それは間違っているようではない。私は何か見落としてますか?
#include "stdafx.h"
using namespace std;
float point[3][1];
float point_trans[3][1] = {0,0,0};
float rot[3][3] = { {1,2,3},{4,5,6},{7,8,9} };
float d[3][1] = {0,0,0};
float x,y,z;
float transform (float x1, float y1, float z1)
{
point[0][0] = x1;
point[1][0] = y1;
point[2][0] = z1;
for(int i=0; i<3; ++i)
{
for(int j=0; j<1; ++j)
{
for(int k=0; k<3; ++k)
{
point_trans[i][j]+=rot[i][k]*point[k][j];
}
}
}
x1 = point_trans[0][0] + d[0][0];
y1 = point_trans[1][0] + d[1][0];
z1 = point_trans[2][0] + d[2][0];
return(x1,y1,z1);
}
int main()
{
x = 6; y = 7; z = 8;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout << rot[i][j] << " ";
}
cout << endl;
}
(x,y,z) = transform(x,y,z);
cout << "X:" << x << " " << "Y:"<<y<<" "<<"Z:"<<z<<endl;
system("pause");
return 0;
}
「小さなプログラムをデバッグする方法」(https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)については、しばらくお待ちください。 –
どのような結果が期待されているのですか?なぜ、どのような結果が得られますか?また、行列の乗算が問題であると考える場合は、行列の乗算を行う関数では何も分離しないでください。 – Beta
行列の乗算はうまくいきますが、関数からcppの3つの値を返すことはできません。 – Chandini