旋转矩阵

原理
二维与三维的 旋转矩阵

% matlab 

% This function finds the optimal Rigid/Euclidean transform in 3D space
% It expects as input a Nx3 matrix of 3D points.
% It returns R, t
% You can verify the correctness of the function by copying and pasting these commands:
%
R = orth(rand(3,3)); % random rotation matrix
if det(R) < 0
    V(:,3) = -V(:,3);
    R = V*U';
end
t = rand(3,1); % random translation
n = 10; % number of points
A = rand(n,3);
B = R*A' + repmat(t, 1, n);
B = B';
[ret_R, ret_t] = rigid_transform_3D1(A, B);
A2 = (ret_R*A') + repmat(ret_t, 1, n)
A2 = A2'
% Find the error
err = A2 - B;
err = err .* err;
err = sum(err(:));
rmse = sqrt(err/n);
disp(sprintf("RMSE: %f", rmse));
disp("If RMSE is near zero, the function is correct!");
%}

% expects row data
function [R,t] = rigid_transform_3D1(A, B)
    if nargin ~= 2
	    error("Missing parameters");
    end
    %assert(size(A) == size(B))
    centroid_A = mean(A);
    centroid_B = mean(B);
    N = size(A,1);
    H = (A - repmat(centroid_A, N, 1))' * (B - repmat(centroid_B, N, 1));
    [U,S,V] = svd(H);
    R = V*U';
    if det(R) < 0
        printf("Reflection detected\n");
        V(:,3) = -1*V(:,3);
        R = V*U';
    end
    t = -R*centroid_A' + centroid_B';
end



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值