write a function to translate a 3d object
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jiaoying Ren
le 27 Août 2019
Commenté : Jiaoying Ren
le 27 Août 2019
Help!
So I have this assignment that ask me to write a function to translate this object
load tetmesh
TR = triangulation(tet,X);
[FBtri,FBpoints] = freeBoundary(TR);
T = FBtri;
S = FBpoints' - [zeros(1,1079);zeros(1,1079);40*ones(1,1079)];
to show the object, use the code given by
function show(T,S)
trisurf(T,S(1,:),S(2,:),S(3,:),'FaceColor','cyan','FaceAlpha', 0.8);
axis([-120 120 -120 120 -120 120])
xlabel('x')
ylabel('y')
zlabel('z')
end
the first part of my assignment is "Write a function shift.m which takes as input a 3 × n matrix S (for example, as obtained from running setup.m), a scalar dist which gives the distance that the object should translate, and a string ’x’, ’y’, or ’z’ which tells which axis you want to translate along. "
My attempt is
function shift(S,dist,axis)
n = size(S,2);
B = ones(1,n);
if axis == 'x'
S = S + [dist;0;0]*B; % move along x-axis
elseif axis =='y'
S = S + [0;dist;0]*B; % move along y-axis
else
S = S + [0;0;dist] * B; % move along z-axis
end
end
However, this doesn't quite work because I got this error message when I was trying it out.
>> show2(T,shift(S,80,'y'))
Error using shift
Too many output arguments.
So I'm just wondering where I did wrong and how I can fix it. Any help is greatly appreciated!
Thx in advance!
0 commentaires
Réponse acceptée
James Tursa
le 27 Août 2019
You didn't write your function to return an output. Try this:
function S = shift(S,dist,axis)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Performance dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!