Problem with the rotated object shape

I have written a code for generating egg shape from ellipse using the model explained in the link below optimal shape of avian egg.The ellipse that i have generated is using normal parametric equations. x = a*cos(theta) y = b* sin(theta) Below is the figure of ellipse along with the egg shape generated by the model explained in the link above.
</matlabcentral/answers/uploaded_files/57944/ellipse%20and%20egg%20shape.jpg> next I tried to rotate the egg shape by angle pi/2 using transformation matrix; but this is what i get.
</matlabcentral/answers/uploaded_files/57945/rotated%20egg%20shape.jpg> My question is why am I not getting a proper egg shape in the rotated version?I get proper figure for an angle of pi.but not for any other angles .... pi/6,pi/3 etc....

Réponses (1)

KSSV
KSSV le 17 Août 2016
I don't know how you have rotated the object/ geometry; I cannot even open the links you have given. You may consider the below code, which may help you.
clc; clear all ;
s = [-1 -1 ; -1 1 ; 1 1 ; 1 -1 ; -1 -1]' ; % draw square
plot(s(1,:),s(2,:),'r') ;
%%rotate the object
th = pi/4 ; % rotate by 45 degrees
R = [cos(th) -sin(th) ; sin(th) cos(th)] ; % rotation matrix
S = zeros(size(s)) ; % initialize rotated coordinates
for i = 1:size(s,2)
S(:,i) = R*s(:,i) ;
end
hold on
plot(S(1,:),S(2,:),'b') ;

6 commentaires

Radhika Bhagwat
Radhika Bhagwat le 17 Août 2016
thank you for the reply. yes I too have done the rotation using same method. but after rotation the egg shape that I get is a compressed version . Have tried to load the figures once again.
KSSV
KSSV le 17 Août 2016
Attach your code here...
here is the code:
%%generating ellipse
a = 30;b=20;
etheta = [0:0.01:2*pi];
ex = a .*cos(etheta);
ey = b .* sin(etheta);
figure();plot(ex,ey);
%%getting egg shape from ellipse
newex = ex;
c0 = 1;c1 = 0.2;c2 =0; c3=0;
exdash = newex./a;
efun = c0+c1.*exdash+c2.*exdash.^2+c3.*exdash.^3;
newey = ey.*efun;
figure();plot(newex,newey,'color','red');
%%rotate egg shape by pi/2
ealpha = pi/2;
ec= cos(ealpha);es = sin(ealpha);
EQ = [ec -es;es ec];
enew = EQ*[newex;newey];
figure();plot(enew(1,:),enew(2,:));
KSSV
KSSV le 17 Août 2016
I think the code is working fine.....I calculated area of the egg, in both the cases it is same. I don't think there is any problem with rotated egg..
Radhika Bhagwat
Radhika Bhagwat le 17 Août 2016
so then why is it looking compressed? do i need to adjust the figure window size? cause doing that gives a proper view. but then do i have to keep adjusting the window size for every angle ?Below is the adjusted figure window displaying egg shape for pi/2;
William Chamberlain
William Chamberlain le 3 Oct 2018
Modifié(e) : William Chamberlain le 3 Oct 2018
Add
axis equal
at the end? And use
xlim( [] ) ; ylim( [] ) ;
to control the axes extent.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactions, Camera Views, and Lighting dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by