Moving a Matrix?

4 Ansichten (letzte 30 Tage)
Dylan
Dylan am 30 Aug. 2011
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.

Antworten (1)

pangyuteng
pangyuteng am 30 Aug. 2011
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/

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by