Scaling/Tr​ansposing/​Rotating surface object

1 visualizzazione (ultimi 30 giorni)
Yordan
Yordan il 12 Feb 2014
Risposto: Fady Hanna il 20 Mar 2019
So i create a cylinder on a plane 100 100 100. I have a matrix I used before in class for scaling and plotting an object file but I can figure out how to apply it here. Here is the source
function kine()
close all;
addpath( genpath( '.' ) );
set( gca, 'XLim',[0 100], 'YLim',[0 100], 'ZLim',[0 100] );
set(gcf, 'Color', 'k' );
box on;
grid on;
whitebg(1,'w');
% Sample values
h = 30; % height
ra = 4; % radius
% Create constant vectors
tht = linspace(0,2*pi,20); z = linspace(0,h,20);
% Create cylinder
xa = repmat(ra*cos(tht),20,1); ya = repmat(ra*sin(tht),20,1);
za = repmat(z',1,20);
% To close the ends
X = [xa*0; flipud(xa); (xa(1,:))*0]; Y = [ya*0; flipud(ya); (ya(1,:))*0];
Z = [za; flipud(za); za(1,:)];
hold on;
% Draw cylinder
V = surf(X,Y,Z);
V = V';
V = [ V; ones( 1, size(V,2) ) ];
S = [ 0.5 0.0 0.0 0.0; ...
0.0 1.0 0.0 0.0; ...
0.0 0.0 1.0 0.0; ...
0.0 0.0 0.0 1.0];
V1 = S * V;
surf(V1(1,:),V1(2,:),V1(3,:));
hold on;
end
thank you
  1 Commento
Matt J
Matt J il 12 Feb 2014
In future, please highlight your code and apply the
formatting button, as I have just done for you now.

Accedi per commentare.

Risposte (1)

Fady Hanna
Fady Hanna il 20 Mar 2019
function kine()
close all;
addpath( genpath( '.' ) );
set( gca, 'XLim',[0 100], 'YLim',[0 100], 'ZLim',[0 100] );
set(gcf, 'Color', 'k' );
box on;
grid on;
whitebg(1,'w');
% Sample values
h = 30; % height
ra = 4; % radius
% Create constant vectors
tht = linspace(0,2*pi,20); z = linspace(0,h,20);
% Create cylinder
xa = repmat(ra*cos(tht),20,1); ya = repmat(ra*sin(tht),20,1);
za = repmat(z',1,20);
% To close the ends
X = [xa*0; flipud(xa); (xa(1,:))*0]; Y = [ya*0; flipud(ya); (ya(1,:))*0];
Z = [za; flipud(za); za(1,:)];
hold on;
% Draw cylinder
V = surf(X,Y,Z);
V = V';
V = [ V; ones( 1, size(V,2) ) ];
S = [ 0.5 0.0 0.0 0.0; ...
0.0 1.0 0.0 0.0; ...
0.0 0.0 1.0 0.0; ...
0.0 0.0 0.0 1.0];
V1 = S * V;
surf(peaks(100),'Parent',t)
hold on;
end
thank you

Categorie

Scopri di più su Discrete Data Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by