Moving a Matrix?
3 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have a 3d surface object in a matlab matrix in a basic form:
The matrix has x and y and the values of the cell are the height information, z I want to move the object within the matrix, and I have the transformation matrix, but I don't know how to apply it to the matrix.
Here are the details of the movement:
c: the translation component
T: the orthogonal rotation and reflection component
b: the scale component
transform.T
ans = 0.9888 -0.1324 -0.0695
0.1342 0.9907 0.0208
0.0661 -0.0298 0.9974
transform.b
ans =
0.8899
transform.c
ans =
-68.8506 -165.9485 -6.9946
-68.8506 -165.9485 -6.9946
-68.8506 -165.9485 -6.9946
ANY help would be really appreciated.
0 件のコメント
回答 (1 件)
pangyuteng
2011 年 8 月 30 日
Hope the following example code helps.
%create and plot example data.
[X,Y,Z] = peaks(30);
figure(1)
hsp=surfc(X,Y,Z);
title('original');
%create whatever matrices you want.
Mt = makehgtform;% returns an identity transform.
Mt(1:3,1:3)=[0.9888, -0.1324, -0.0695;...
0.1342 0.9907 0.0208;...
0.0661 -0.0298 0.9974];
% create scaling matrix
Mb = makehgtform('scale', [0.8899 0.8899 0.8899]);
% create translation matrix
Mc = makehgtform('translate',[-68.8506 -165.9485 -6.9946]);
%format the points for transfomration.
points=([X(:)';Y(:)';Z(:)';ones(size(Z(:)))']);
%transform the points, note the order of the matrices
tPoints = Mc*Mb*Mt*points;
%get the transformed coordinates of the example object
tX = reshape(tPoints(1,:),size(X));
tY = reshape(tPoints(2,:),size(X));
tZ = reshape(tPoints(3,:),size(X));
figure(2)
hsp=surfc(tX,tY,tZ);
title('transformed');
search "transformation matrix" for more info, e.g., http://www.senocular.com/flash/tutorials/transformmatrix/
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Object Containers についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!