storing script outputs as an array
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I wanted to try identifying convex polygons by their projected widths. How can I get the outputs, D, stored in a compact array that I can save and work with?
%loop that will have 1440 iterations (each iteration
%representing a rotation of the plane by 0.5 degrees)
for t= 1:2000
format('long')
%imagine points in 2-dimensional euclidean space. These three vectors
%represent the three vertices of an equilateral triangle cetered at the
%origin
A=[0;1];
B=[-0.86603; -0.50000];
C=[0.86603; 0.50000];
%T is designed to be a 0.5 degree counter-clockwise rotation matrix, sending each
%of the previous vectors to their 0.5 degree rotated counterparts
T= [ 0.99996 -0.00873;0.00873 0.99996];
%P extracts the x values of each vector above, discarding the rest
P= [1 0];
%represent the rotated images of A,B,C, for some iteration 't'
tA=(T^t)*A;
tB=(T^t)*B;
tC=(T^t)*C;
%represent the projection of tA,tB,tC onto the x-axis.
imA=P*tA;
imB=P*tB;
imC=P*tC;
%distances between the respective projections
distAB=abs(imA-imB);
distBC=abs(imB-imC);
distCA=abs(imC-imA);
%making a vector V with elements 'distAB' 'distBC' 'distCA'
X=[1 0 0];
Y=[0 1 0];
Z=[0 0 1];
dX=distAB*X;
dY=distBC*Y;
dZ=distCA*Z;
V= dX+dY+dZ;
% D = max element in V is the width of the 'shadow' of the triangle on the
%x-axis
D=max(V)
end
2 commentaires
Réponses (1)
per isakson
le 15 Mar 2017
Modifié(e) : per isakson
le 15 Mar 2017
I guess: this is what you try to do.
D = nan( 1, 2000 );
format('long')
%imagine points in 2-dimensional euclidean space. These three vectors
%represent the three vertices of an equilateral triangle cetered at the
%origin
A=[0;1];
B=[-0.86603; -0.50000];
C=[0.86603; 0.50000];
%T is designed to be a 0.5 degree counter-clockwise rotation matrix, sending each
%of the previous vectors to their 0.5 degree rotated counterparts
T= [ 0.99996 -0.00873;0.00873 0.99996];
%P extracts the x values of each vector above, discarding the rest
P= [1 0];
for t= 1:2000
%represent the rotated images of A,B,C, for some iteration 't'
tA=(T^t)*A;
tB=(T^t)*B;
tC=(T^t)*C;
%
%represent the projection of tA,tB,tC onto the x-axis.
imA=P*tA;
imB=P*tB;
imC=P*tC;
%
%distances between the respective projections
distAB=abs(imA-imB);
distBC=abs(imB-imC);
distCA=abs(imC-imA);
%
%making a vector V with elements 'distAB' 'distBC' 'distCA'
X=[1 0 0];
Y=[0 1 0];
Z=[0 0 1];
%
dX=distAB*X;
dY=distBC*Y;
dZ=distCA*Z;
V= dX+dY+dZ;
%
% D = max element in V is the width of the 'shadow' of the triangle on the
%x-axis
D(t)=max(V);
end
especially note
D = nan( 1, 2000 );
...
D(t) = max(V);
in the original code D was overwritten two thousand times
Voir également
Catégories
En savoir plus sur Computational Geometry 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!