object_transform.m

来自「用MATLAB做的3D图形的变化,这个是范例,希望会帮到大家」· M 代码 · 共 115 行

M
115
字号
close all;
clear all;

basis = [
   [1 0];
   [0 0];
   [0 1];
]';

square = [
  [ 1  1]
  [-1  1];
  [-1 -1];
  [ 1 -1];
  [ 1  1];
]';

% differential scale
S = [ 1.2  0;
        0  0.8];
% rotation
theta = pi/4;
R = [cos(theta) sin(theta);
       -sin(theta) cos(theta)];
% shear
Q = [ 1 1.2;
         0 1];
       
% The active interpretation
figure;
hold on;
axis equal;
plot( sqrt(3), sqrt(3), 'w.' );
plot( -sqrt(3), -sqrt(3), 'w.' );
plot( basis(1,:), basis(2,:), 'k');
plot( square(1,:), square(2,:), 'b');
obj = S*square;
plot( obj(1,:), obj(2,:), 'r');

figure;
hold on;
axis equal;
plot( sqrt(3), sqrt(3), 'w.' );
plot( -sqrt(3), -sqrt(3), 'w.' );
plot( basis(1,:), basis(2,:), 'k');
plot( square(1,:), square(2,:), 'b');
obj = R*square;
plot( obj(1,:), obj(2,:), 'r');

figure;
hold on;
axis equal;
plot( sqrt(3), sqrt(3), 'w.' );
plot( -sqrt(3), -sqrt(3), 'w.' );
plot( basis(1,:), basis(2,:), 'k');
plot( square(1,:), square(2,:), 'b');
obj = Q*square;
plot( obj(1,:), obj(2,:), 'r');

figure;
hold on;
axis equal;
plot( sqrt(3), sqrt(3), 'w.' );
plot( -sqrt(3), -sqrt(3), 'w.' );
plot( basis(1,:), basis(2,:), 'k');
plot( square(1,:), square(2,:), 'b');
M = (Q*R*S);
obj = M*square;
plot( obj(1,:), obj(2,:), 'r');


% The passive interpretation
figure;
hold on;
axis equal;
plot( sqrt(3), sqrt(3), 'w.' );
plot( -sqrt(3), -sqrt(3), 'w.' );
plot( basis(1,:), basis(2,:), 'k');
plot( square(1,:), square(2,:), 'b');
obj = S^(-1)*basis;
plot( obj(1,:), obj(2,:), 'r');

figure;
hold on;
axis equal;
plot( sqrt(3), sqrt(3), 'w.' );
plot( -sqrt(3), -sqrt(3), 'w.' );
plot( basis(1,:), basis(2,:), 'k');
plot( square(1,:), square(2,:), 'b');
obj = R^(-1)*basis;
plot( obj(1,:), obj(2,:), 'r');

figure;
hold on;
axis equal;
plot( sqrt(3), sqrt(3), 'w.' );
plot( -sqrt(3), -sqrt(3), 'w.' );
plot( basis(1,:), basis(2,:), 'k');
plot( square(1,:), square(2,:), 'b');
obj = Q^(-1)*basis;
plot( obj(1,:), obj(2,:), 'r');

figure;
hold on;
axis equal;
plot( sqrt(3), sqrt(3), 'w.' );
plot( -sqrt(3), -sqrt(3), 'w.' );
plot( basis(1,:), basis(2,:), 'k');
plot( square(1,:), square(2,:), 'b');
M = (Q*R*S);
obj = M^(-1)*basis;
plot( obj(1,:), obj(2,:), 'r');


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?