|
11 | 11 | % See also background, ground_track. |
12 | 12 | % |
13 | 13 | % Copyright © 2021 Tamas Kis |
14 | | -% Last Update: 2023-05-17 |
| 14 | +% Last Update: 2023-05-20 |
15 | 15 | % Website: https://tamaskis.github.io |
16 | 16 | % Contact: tamas.a.kis@outlook.com |
17 | 17 | % |
18 | | -% TECHNICAL DOCUMENTATION: |
| 18 | +% Technical Documentation: |
19 | 19 | % https://tamaskis.github.io/files/Visualizing_Celestial_Bodies_in_3D.pdf |
20 | 20 | % |
21 | 21 | %-------------------------------------------------------------------------- |
22 | 22 | % |
23 | 23 | % ------ |
24 | 24 | % INPUT: |
25 | 25 | % ------ |
26 | | -% planet - (OPTIONAL) (char) 'Sun', 'Moon', 'Mercury', 'Venus', |
27 | | -% 'Earth', 'Earth Cloudy', 'Earth Coastlines', |
| 26 | +% planet - (OPTIONAL) (char array) 'Sun', 'Moon', 'Mercury', |
| 27 | +% 'Venus', 'Earth', 'Earth Cloudy', 'Earth Coastlines', |
28 | 28 | % 'Earth Night', 'Earth Night Cloudy', 'Mars', |
29 | 29 | % 'Jupiter', 'Saturn', 'Uranus', 'Neptune', or 'Pluto' |
30 | 30 | % (defaults to 'Earth Cloudy') |
31 | 31 | % opts - (OPTIONAL) (1×1 struct) plot options |
32 | | -% • Clipping - (char) 'on' or 'off' (defaults to 'off') |
33 | | -% --> if 'on', the surface will be "clipped" to fit |
34 | | -% the axes when zooming in |
35 | | -% • Color - (char or 1×3 double) line color (only relevant |
| 32 | +% • Clipping - (char array) 'on' or 'off' (defaults to 'off') |
| 33 | +% • if 'on', the surface will be "clipped" to fit the |
| 34 | +% axes when zooming in |
| 35 | +% • Color - (char array or 1×3 double) line color (only relevant |
36 | 36 | % when drawing Earth coastlines) |
37 | | -% --> can be specified as a name, short name, or RGB |
38 | | -% triplet [rgb] |
| 37 | +% • can be specified as a name, short name, or RGB |
| 38 | +% triplet [rgb] |
39 | 39 | % • FaceAlpha - (1×1 double) 0 for 100% transparency, 1 for 100% |
40 | 40 | % opacity |
41 | 41 | % • LineWidth - (1×1 double) line width (only relevant when drawing |
42 | 42 | % Earth coastlines) |
43 | | -% • LineStyle - (char) line style (only relevant when drawing Earth |
44 | | -% coastlines) |
| 43 | +% • LineStyle - (char array) line style (only relevant when drawing |
| 44 | +% Earth coastlines) |
45 | 45 | % • Position - (3×1 double) position of planet's geometric center |
46 | | -% • RefPlane - (char) 'equatorial' or 'ecliptic' |
| 46 | +% • RefPlane - (char array) 'equatorial' or 'ecliptic' |
47 | 47 | % • RotAngle - (1×1 double) rotation angle [deg] |
48 | | -% • Units - (char) 'AU', 'ft', 'km', 'm', 'mi', or 'nmi' |
| 48 | +% • Units - (char array) 'AU', 'ft', 'km', 'm', 'mi', or 'nmi' |
49 | 49 | % |
50 | 50 | % ------- |
51 | 51 | % OUTPUT: |
|
55 | 55 | % ----- |
56 | 56 | % NOTE: |
57 | 57 | % ----- |
58 | | -% --> All fields of "opts" do NOT have to be defined; when a field is |
59 | | -% left undefined, the rest of the plot settings are set to default |
60 | | -% values. |
61 | | -% --> Use the "background" function included with download to set the |
62 | | -% plot background. When using "background" to set the plot |
63 | | -% background, the function call on "background" must occur BEFORE the |
64 | | -% function call on "planet3D", otherwise the background will be |
65 | | -% 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. |
| 58 | +% • All fields of "opts" do NOT have to be defined; when a field is left |
| 59 | +% undefined, the rest of the plot settings are set to default values. |
| 60 | +% • Use the "background" function included with download to set the plot |
| 61 | +% background. When using "background" to set the plot background, the |
| 62 | +% function call on "background" must occur BEFORE the function call on |
| 63 | +% "planet3D", otherwise the background will be plotted over the |
| 64 | +% celestial body. |
| 65 | +% • If you want to produce separate plots on separate figures using the |
| 66 | +% "planet3D" function, always use the "drawnow" command before |
| 67 | +% initializing a new figure to ensure that the correct plots are drawn |
| 68 | +% on the correct figures. |
70 | 69 | % |
71 | 70 | %========================================================================== |
72 | 71 | function planet_surface = planet3D(planet,opts) |
|
276 | 275 | % Performs translation. |
277 | 276 | % --------------------- |
278 | 277 |
|
| 278 | + % translates coordinates of surface object |
279 | 279 | planet_surface.XData = planet_surface.XData+position(1); |
280 | 280 | planet_surface.YData = planet_surface.YData+position(2); |
281 | 281 | planet_surface.ZData = planet_surface.ZData+position(3); |
282 | 282 |
|
| 283 | + % translates coordinates of Earth coastlines |
| 284 | + if strcmpi(planet,'Earth Coastlines') |
| 285 | + x_coast = x_coast+position(1); |
| 286 | + y_coast = y_coast+position(1); |
| 287 | + z_coast = z_coast+position(1); |
| 288 | + end |
| 289 | + |
283 | 290 | % -------------------------------------------------------------- |
284 | 291 | % Drawing additional lines (i.e. coastlines or rings of Saturn). |
285 | 292 | % -------------------------------------------------------------- |
|
315 | 322 | % speed - we plot the bands of Saturns rings as individual lines |
316 | 323 | % and don't want to plot thousands of lines) - this shrinking |
317 | 324 | % process is condensed from the reduced_data_points function (see |
318 | | - % https://www.mathworks.com/matlabcentral/fileexchange/86218-reduce |
319 | | - % -number-of-data-points-reduce_data_points) |
| 325 | + % https://github.com/tamaskis/Useful_Functions_for_MATLAB-MATLAB/ |
| 326 | + % blob/main/functions/reduce_data_points.m) |
320 | 327 | n_new = 200; |
321 | 328 | colors = colors(1:round(n/n_new):n,:); |
322 | 329 |
|
|
333 | 340 | % the planet s(https://en.wikipedia.org/wiki/Rings_of_Saturn) |
334 | 341 | r = conversion_factor*(R+7000000+((80000000-7000000)/n_new)*i); |
335 | 342 |
|
336 | | - % x, y, and z coordinates of Saturns rings in equatorial plane |
337 | | - x_ring = position(1)+r*cos(theta); |
338 | | - y_ring = position(2)+r*sin(theta); |
339 | | - z_ring = position(3)*ones(size(theta)); |
| 343 | + % x, y, and z coordinates of Saturns rings in equatorial plane, |
| 344 | + % centered at origin |
| 345 | + x_ring = r*cos(theta); |
| 346 | + y_ring = r*sin(theta); |
| 347 | + z_ring = ones(size(theta)); |
340 | 348 |
|
341 | | - % rotates rings to equatorial plane (uses same rotation matrix |
342 | | - % as tilting the planet earlier in code) |
| 349 | + % tilts rings |
343 | 350 | new_coordinates = R1*[x_ring;y_ring;z_ring]; |
344 | 351 | x_ring = new_coordinates(1,:); |
345 | 352 | y_ring = new_coordinates(2,:); |
346 | 353 | z_ring = new_coordinates(3,:); |
347 | 354 |
|
| 355 | + % centers rings on main body |
| 356 | + x_ring = x_ring+position(1); |
| 357 | + y_ring = y_ring+position(1); |
| 358 | + z_ring = z_ring+position(1); |
| 359 | + |
348 | 360 | % plots the jth ring |
349 | 361 | plot3(x_ring,y_ring,z_ring,'Color',colors(i,:)); |
350 | 362 |
|
|
0 commit comments