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

本例子只有旋转,没有平移

#include <iostream>
#include <GTEngine/Mathematics/GteConvertCoordinates.h>
using namespace gte;

// #define Vector4<double> Vector<4, double>
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, A, B;
	bool isRHU, isRHV;
	// U.SetCol(0,  Vector<4, double>{1.0, 0.0, 0.0, 0.0});
	// U.SetCol(1,  Vector<4, double>{0.0, 1.0, 0.0, 0.0});
	// U.SetCol(2,  Vector<4, double>{0.0, 0.0, 1.0, 0.0});
	// U.SetCol(3,  Vector<4, double>{0.0, 0.0, 0.0, 1.0});
	
	// V.SetCol(0,  Vector<4, double>{0.866, 0.5, 0.0, 0.0});
	// V.SetCol(1,  Vector<4, double>{-0.5, 0.866, 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});

    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, 0.0, 1.0, 0.0});
	U.SetCol(3,  Vector<4, double>{0.0, 0.0, 0.0, 1.0});
	convert(U, true, V, false);

    // Matrix<4, 4, double> matrix; 
    // matrix = convert.GetC();
    
    // for(int i = 0; i <4 ; i++)
    // {
    //      Vector<4,double > row = matrix.GetRow(i);
        
    //     for(size_t j = 0; j < 4; j++)
    //     {
	//         std::cout<< row[i]<<" ";
    //     }
    //     std::cout<<std::endl;
        
    // }
    
	isRHU = convert.IsRightHandedU();  // false
	isRHV = convert.IsRightHandedV();  // true
    // std::cout<<isRHU<<std::endl;
    // std::cout<<isRHV<<std::endl;
	X = { 0.0, 2.0, 0, 1.0 };

	Y = convert.UToV(X);  //
    
    for(int i = 0; i < 4; i++)
    {
     std::cout<<"Y  "<< i<<": " <<Y[i]<<std::endl;
    }
    
	// std::cout<<"Y   "<<Y<<std::endl;
	P0 = U*X;
	P1 = V*Y;
	diff = P0 - P1;  // { 0, 0, 0, 0 }
	return 0;
}

编译:

 g++ gte_test.cpp -I/usr/local/include/GTEngine -std=c++11 -L/home/itfanr/GeometricTools/GTEngine/lib/Release -lgtengine

输出:

itfanr@itfanr-pc:test$ ./a.out
Y  0: -1
Y  1: 1.732
Y  2: 0
Y  3: 1

对比《机器人学导论》中的例子:
在这里插入图片描述

  • 4
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值