Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Rotation of an ellipse in 3D

Subject: Rotation of an ellipse in 3D

From: kawak

Date: 21 Jan, 2010 00:31:04

Message: 1 of 1

Hi,

I am writing a matlab code which will enable me to simulate the orbits of the Earth, an asteroid and Mars around the Sun.

First of all, I did in 2D:

function [E,J,M]=plotter(ae,ee,Pe,aj,ej,Pj,am,em,Pm)

step=pi/20;
theta=0:step:2*pi;
    
    %Plot of the Sun
hold on
%e=eccentricity
e=0;
%a=semimajor axis
a=0;
R=(a.*(1-e.^2))./(1-e*cos(theta));
polar(theta,R,'y O');

    %Plot of the Earth
E=(ae.*(1-ee.^2))./(1-ee*cos(theta));
polar(theta,E,'b . -');
pause

    %Plot of 1999 JU3
J=(aj.*(1-ej.^2))./(1-ej*cos(theta));
polar(theta,J,'g . -');
pause

    %Plot of Mars
M=(am.*(1-em.^2))./(1-em*cos(theta));
polar(theta,M,'R . -'); grid on;
pause
  
legend('Sun','Earth','1999 JU3','Mars')
hold off
figure;


hold on
%Polar to cartesien
[xe,ye]=pol2cart(theta,E);
%Earth's ellipse does a 0.005° offset with the coplanar ellipse
xye(:,1)=cosd(0.005).*xe+sind(0.005).*ye;
xye(:,2)=-sind(0.005).*xe+cosd(0.005).*ye;
plot(xe,ye,'b',xye(:,1),xye(:,2),'b')

[xj,yj]=pol2cart(theta,J);
%Astereoide's ellipse does a 5.6° offset with the coplanar ellipse
xyj(:,1)=cosd(5.6).*xj+sind(5.6).*yj;
xyj(:,2)=-sind(5.6).*xj+cosd(5.6).*yj;
plot(xj,yj,'g',xyj(:,1),xyj(:,2),'g')

[xm,ym]=pol2cart(theta,M);
%Mars' ellipse does a 1.8° offset with the coplanar ellipse
xym(:,1)=cosd(1.8).*xm+sind(1.8).*ym;
xym(:,2)=-sind(1.8).*xm+cosd(1.8).*ym;
plot(xm,ym,'r',xym(:,1),xym(:,2),'r');grid;
hold off
end

This code works however it displays the orbits in 2D. For the user, it will be easier to display the orbits in 3D. However I have not got a clue to obtain the orbits in 3D.

Can you help me?

Thank you

Benjamin

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us