Skip to content

Commit e940172

Browse files
committed
made all inputs optional
1 parent e74d726 commit e940172

File tree

4 files changed

+43
-44
lines changed

4 files changed

+43
-44
lines changed
-268 Bytes
Binary file not shown.

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@ Creates high-resolution renderings of the Earth and the major celestial bodies i
44

55
## Syntax
66

7+
`planet3D`\
78
`planet3D(planet)`\
89
`planet3D(planet,opts)`\
910
`planet_surface = planet3D(__)`
1011

11-
**NOTE:** Use the `background` function (see below) to set the plot background. When using `background` to set the plot background, the function call on `background` must occur *before* the function call on `planet3D`, otherwise the background will be plotted *over* the celestial body.
12+
**NOTE:**
13+
- Use the `background` function (see below) to set the plot background. When using `background` to set the plot background, the function call on `background` must occur *before* the function call on `planet3D`, otherwise the background will be plotted *over* the celestial body.
14+
- If you want to produce separate plots on separate figures using the `planet3D` function, always use the [`drawnow`](https://www.mathworks.com/help/matlab/ref/drawnow.html) command before initializing a new figure to ensure that the correct plots are drawn on the correct figures.
1215

1316

1417
## Description
1518

16-
`planet3D(planet)` draws the celestial body specified by `planet`, which can be input as `'Sun'`, `'Moon'`, `'Mercury'`, `'Venus'`, `'Earth'`, `'Earth Cloudy'`, `'Earth Night'`, `'Earth Night Cloudy'`, `'Earth Coastlines'`, `'Mars'`, `'Jupiter'`, `'Saturn'`, `'Uranus'`, `'Neptune'`, or `'Pluto'`.
19+
`planet3D` draws the Earth with clouds. Units are in meters by default.
20+
21+
`planet3D(planet)` draws the celestial body specified by `planet`, which can be input as `'Sun'`, `'Moon'`, `'Mercury'`, `'Venus'`, `'Earth'`, `'Earth Cloudy'`, `'Earth Night'`, `'Earth Night Cloudy'`, `'Earth Coastlines'`, `'Mars'`, `'Jupiter'`, `'Saturn'`, `'Uranus'`, `'Neptune'`, or `'Pluto'`. Units are in meters by default.
1722

1823
`planet3D(planet,opts)` does the same as the syntax above, but allows for the specification of optional plotting parameters. `opts` is a struct that has the following fields:
1924
- `Clipping` → `'on'` if surfaces should be "[clipped](https://www.mathworks.com/help/matlab/creating_plots/clipping-in-plots-and-graphs.html)" to fit axes, `'off'` otherwise (defaults to `off`)
@@ -28,7 +33,8 @@ Creates high-resolution renderings of the Earth and the major celestial bodies i
2833

2934
`planet_surface = planet3D(__)` does the same as the previous two syntaxes, but also returns the `Surface` object defining the planet.
3035

31-
**NOTE:** All fields of `opts` do NOT have to be defined; when a field is left undefined, the rest of the plot settings are set to default values. Additionally, `Color`, `LineWidth`, and `LineStyle` are only relevant when plotting the Earth's coastlines.
36+
**NOTE:**
37+
- All fields of `opts` do NOT have to be defined; when a field is left undefined, the rest of the plot settings are set to default values. Additionally, `Color`, `LineWidth`, and `LineStyle` are only relevant when plotting the Earth's coastlines.
3238

3339

3440

planet3D/background.m

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
% See also planet3D, ground_track.
88
%
99
% Copyright © 2021 Tamas Kis
10-
% Last Update: 2021-12-12
10+
% Last Update: 2022-04-20
1111
% Website: https://tamaskis.github.io
1212
% Contact: tamas.a.kis@outlook.com
1313
%
1414
% TECHNICAL DOCUMENTATION:
1515
% https://tamaskis.github.io/documentation/Visualizing_Celestial_Bodies_in_3D.pdf
1616
%
17-
% REFERENCES:
18-
% [1] https://www.solarsystemscope.com/textures/
19-
%
2017
%--------------------------------------------------------------------------
2118
%
2219
% ------

planet3D/planet3D.m

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,32 @@
33
% planet3D Creates high-resolution renderings of the Earth and the major
44
% celestial bodies in our solar system for space mechanics applications.
55
%
6+
% planet3D
67
% planet3D(planet)
78
% planet3D(planet,opts)
89
% planet_surface = planet3D(__)
910
%
1011
% See also background, ground_track.
1112
%
1213
% Copyright © 2021 Tamas Kis
13-
% Last Update: 2021-12-12
14+
% Last Update: 2022-04-20
1415
% Website: https://tamaskis.github.io
1516
% Contact: tamas.a.kis@outlook.com
1617
%
1718
% TECHNICAL DOCUMENTATION:
1819
% https://tamaskis.github.io/documentation/Visualizing_Celestial_Bodies_in_3D.pdf
1920
%
20-
% REFERENCES:
21-
% [1] https://mathworks.com/matlabcentral/fileexchange/27123-earth-sized-sphere-with-topography
22-
% [2] https://apps.dtic.mil/sti/pdfs/AD1000581.pdf
23-
% [3] https://www.mathworks.com/matlabcentral/fileexchange/13823-3d-earth-example
24-
% [4] https://nssdc.gsfc.nasa.gov/planetary/factsheet/mercuryfact.html
25-
% [5] https://en.wikipedia.org/wiki/Moon
26-
% [6] https://www.jpl.nasa.gov/images/pluto-color-map
27-
% [7] https://en.wikipedia.org/wiki/Rings_of_Saturn
28-
% [8] https://www.solarsystemscope.com/textures/
29-
% [9] https://en.wikipedia.org/wiki/Sun
30-
% [10] https://visibleearth.nasa.gov/images/57730/the-blue-marble-land-surface-ocean-color-and-sea-ice/57731l
31-
% [11] Vallado, "Fundamentals of Astrodynamics and Applications", 4th
32-
% Ed., Tables D-3, D-4, and D-5 (pp. 1041-1042)
33-
% [12] https://nssdc.gsfc.nasa.gov/planetary/factsheet/venusfact.html
34-
%
3521
%--------------------------------------------------------------------------
3622
%
3723
% ------
3824
% INPUT:
3925
% ------
40-
% planet - (char) 'Sun', 'Moon', 'Mercury', 'Venus', 'Earth',
41-
% 'Earth Cloudy', 'Earth Coastlines', 'Earth Night',
42-
% 'Earth Night Cloudy', 'Mars', 'Jupiter', 'Saturn',
43-
% 'Uranus', 'Neptune', or 'Pluto'
44-
% opts - (OPTIONAL) (1×1 struct) plot options
26+
% planet - (char) (OPTIONAL) 'Sun', 'Moon', 'Mercury', 'Venus',
27+
% 'Earth', 'Earth Cloudy', 'Earth Coastlines',
28+
% 'Earth Night', 'Earth Night Cloudy', 'Mars',
29+
% 'Jupiter', 'Saturn', 'Uranus', 'Neptune', or 'Pluto'
30+
% (defaults to 'Earth Cloudy')
31+
% opts - (1×1 struct) (OPTIONAL) plot options
4532
% • Clipping - (char) 'on' or 'off' (defaults to 'off')
4633
% --> if 'on', the surface will be "clipped" to fit
4734
% the axes when zooming in
@@ -76,6 +63,10 @@
7663
% background, the function call on "background" must occur BEFORE the
7764
% function call on "planet3D", otherwise the background will be
7865
% plotted over the celestial body.
66+
% --> If you want to produce separate plots on separate figures using the
67+
% "planet3D" function, always use the "drawnow" command before
68+
% initializing a new figure to ensure that the correct plots are
69+
% drawn on the correct figures.
7970
%
8071
%==========================================================================
8172
function planet_surface = planet3D(planet,opts)
@@ -91,7 +82,7 @@
9182
'm' 1;
9283
'mi' 100/160934.4;
9384
'nmi' 1/1852};
94-
85+
9586
% planet/body radius, flattening, obliquity,
9687
% R [m] f [-] obl [deg]
9788
data = {'Sun' 696000e3 0.000009 0;
@@ -114,36 +105,41 @@
114105
% Sets (or defaults) plotting options.
115106
% ------------------------------------
116107

108+
% defaults "planet" to 'Earth Cloudy' if not input
109+
if (nargin == 0) || isempty(planet)
110+
planet = 'Earth Cloudy';
111+
end
112+
117113
% sets position of planet's geometric center (defaults to origin)
118-
if (nargin == 1) || ~isfield(opts,'Position')
114+
if (nargin < 2) || ~isfield(opts,'Position')
119115
position = [0;0;0];
120116
else
121117
position = opts.Position;
122118
end
123119

124120
% sets rotation angle (defaults to 0)
125-
if (nargin == 1) || ~isfield(opts,'RotAngle')
121+
if (nargin < 2) || ~isfield(opts,'RotAngle')
126122
theta = 0;
127123
else
128124
theta = opts.RotAngle;
129125
end
130126

131127
% sets conversion factor (defaults to 1, assuming units of m)
132-
if (nargin == 1) || ~isfield(opts,'Units')
128+
if (nargin < 2) || ~isfield(opts,'Units')
133129
units = 'm';
134130
else
135131
units = opts.Units;
136132
end
137133

138134
% sets reference plane (defaults to equatorial plane)
139-
if (nargin == 1) || ~isfield(opts,'RefPlane')
135+
if (nargin < 2) || ~isfield(opts,'RefPlane')
140136
reference_plane = 'equatorial';
141137
else
142138
reference_plane = opts.RefPlane;
143139
end
144140

145141
% sets transparency (defaults to 1 so celestial body is solid)
146-
if (nargin == 1) || ~isfield(opts,'FaceAlpha')
142+
if (nargin < 2) || ~isfield(opts,'FaceAlpha')
147143
FaceAlpha = 1;
148144
else
149145
FaceAlpha = opts.FaceAlpha;
@@ -157,28 +153,28 @@
157153
end
158154

159155
% sets clipping (defaults to 'off')
160-
if (nargin == 1) || ~isfield(opts,'Clipping')
156+
if (nargin < 2) || ~isfield(opts,'Clipping')
161157
Clipping = 'off';
162158
else
163159
Clipping = opts.Clipping;
164160
end
165161

166162
% sets line color (defaults to default MATLAB color)
167-
if (nargin == 1) || ~isfield(opts,'Color')
163+
if (nargin < 2) || ~isfield(opts,'Color')
168164
Color = [0,0.4470,0.7410];
169165
else
170166
Color = opts.Color;
171167
end
172-
168+
173169
% sets line style (defaults to solid line)
174-
if (nargin == 1) || ~isfield(opts,'LineStyle')
170+
if (nargin < 2) || ~isfield(opts,'LineStyle')
175171
LineStyle = '-';
176172
else
177173
LineStyle = opts.LineStyle;
178174
end
179175

180176
% sets line width (defaults to 0.5)
181-
if (nargin == 1) || ~isfield(opts,'LineWidth')
177+
if (nargin < 2) || ~isfield(opts,'LineWidth')
182178
LineWidth = 0.5;
183179
else
184180
LineWidth = opts.LineWidth;
@@ -217,12 +213,12 @@
217213
else
218214
cdata = imread(strcat('',lower(planet),'.png'));
219215
end
220-
216+
221217
% draws planet
222218
planet_surface = surface(x,y,z,'FaceColor','texture',...
223219
'EdgeColor','none','CData',flipud(cdata),'DiffuseStrength',...
224220
1,'SpecularStrength',0,'FaceAlpha',FaceAlpha);
225-
221+
226222
end
227223

228224
% drawing Earth coastlines
@@ -251,19 +247,19 @@
251247
R3 = [ cosd(theta) sind(theta) 0;
252248
-sind(theta) cosd(theta) 0;
253249
0 0 1];
254-
250+
255251
% transformation matrix for tilt
256252
R1 = [1 0 0;
257253
0 cosd(obl) -sind(obl);
258254
0 sind(obl) cosd(obl)];
259-
255+
260256
% axes for rotations (must be row vectors)
261257
alpha1 = [1,0,0];
262258
alpha2 = (R1*[0;0;1])';
263259

264260
% tilts celestial body if referenced to ecliptic plane
265261
rotate(planet_surface,alpha1,obl);
266-
262+
267263
% rotates celestial body about its 3rd axis
268264
rotate(planet_surface,alpha2,theta);
269265

0 commit comments

Comments
 (0)