已知两个坐标系下的坐标,求坐标系之间的转换矩阵(三)

#include 
#include 
using namespace gte;

int main(int argc, char const *argv[])
{
// // Affine change of basis.
	ConvertCoordinates<4, double> convert;

	Vector<4, double> X, Y, P0, P1, diff;
	Matrix<4, 4, double> U, V;
	bool isRHU, isRHV;

    V.SetCol(0,  Vector<4, double>{1.0, 0.0, 0.0, 0.0});
	V.SetCol(1,  Vector<4, double>{0.0, 1.0, 0.0, 0.0});
	V.SetCol(2,  Vector<4, double>{0.0, 0.0, 1.0, 0.0});
	V.SetCol(3,  Vector<4, double>{0.0, 0.0, 0.0, 1.0});
	
	U.SetCol(0,  Vector<4, double>{0.866, 0.5, 0.0, 0.0});
	U.SetCol(1,  Vector<4, double>{-0.5, 0.866, 0.0, 0.0});
	U.SetCol(2,  Vector<4, double>{0, 0, 1.0, 0.0});
	U.SetCol(3,  Vector<4, double>{10.0, 5.0, 0.0, 1.0});
	convert(U, true, V, true);
    
	// isRHU = convert.IsRightHandedU();  // false
	// isRHV = convert.IsRightHandedV();  // true

	X = { 3.0, 7.0, 0.0, 1.0 };

	Matrix<4, 4, double> matrix;
	matrix = convert.GetInverseC();
	
	std::cout<<"transform matrix----------- " < row = matrix.GetRow(i);
	    
	    for(size_t j = 0; j < 4; j++)
	    {
	        std::cout<< row[j]<<" ";
	    }
	    std::cout< YY;
	YY = matrix * X;
    for(int i = 0; i < 4; i++)
    {
     std::cout<<"YY  "<< i<<": " <> T
// T =

//     0.86600   -0.50000    0.00000   10.00000
//     0.50000    0.86600    0.00000    5.00000
//     0.00000    0.00000    1.00000    0.00000
//     0.00000    0.00000    0.00000    1.00000

// >> T * [1 0 0 0]'
// ans =

//    0.86600
//    0.50000
//    0.00000
//    0.00000

// >> T * [0 1 0 0]'
// ans =

//   -0.50000
//    0.86600
//    0.00000
//    0.00000

// >> T * [0 0 1 0]'
// ans =

//    0
//    0
//    1
//    0

输出:

itfanr@itfanr-pc:test$ g++ gte_test.cpp -I/usr/local/include/GTEngine -std=c++11 -lgtengine -lX11 -lXext -lGL -lEGL -lpng -lpthread -lm 
itfanr@itfanr-pc:test$ ./a.out 
transform matrix----------- 
0.866 -0.5 0 10 
0.5 0.866 0 5 
0 0 1 0 
0 0 0 1 
YY matrix * X ------------- 
YY  0: 9.098
YY  1: 12.562
YY  2: 0
YY  3: 1
Y  UToV----------------
Y  0: 9.098
Y  1: 12.562
Y  2: 0
Y  3: 1

你可能感兴趣的:(算法,机器人)