Very Difficult MATLAB program I am trying to write.

11 visualizaciones (últimos 30 días)
Brian
Brian el 14 de Oct. de 2011
Comentada: Walter Roberson el 20 de Nov. de 2023
I am trying to simulate the phases of the moon. I want to give a representation for the 28 days of the moon cycle (see link ). I am wanting to tackle this problem by using rectangles to shade in the light parts that represent the part of the moon showing. How would I do this if I already know how to physically draw the rectangles, I just dont know how to position or make them the right size?? I have been thinking for hours. Please help.
  6 comentarios
Walter Roberson
Walter Roberson el 14 de Oct. de 2011
Trying to hack together some of the science of orbital mechanics...
The shadow on the moon should instantaneously follow a Great Circle on the moon, where the pole of the Great Circle would be deemed to be normal to the direction to the Sun. I say "instantaneously" because that polar direction is not the same as the actual axial tilt of the moon.
Neither the bright area nor the dark area would form ellipses: for example when less than half of the moon was lit, then the bright area would have corners, one at the top and one at the bottom -- polar wedges.
There is an additional complication, which is that the Moon is inclined approximately 5 degrees in orbit relative to the Earth, so the normal between it and the Sun will differ from Earth's. We thus will not see a completely upright wedge: we observe slightly rotated from that; in particular in the Northern Hemisphere we get to peak at the "bottom" of the Moon a bit more than would naively be expected.
James Tursa
James Tursa el 7 de Sept. de 2017
@IA: Yes, the terminator ("equation of the shadow") is a section of an ellipse since it is just a circle rotated in 3D space. Your approach should work. E.g., just generate a set of bounding points, rotate the points appropriately, and a couple of "fill" commands should do it. I have no idea what the rectangle approach is supposed to do.

Iniciar sesión para comentar.

Respuestas (2)

James Tursa
James Tursa el 7 de Sept. de 2017
Editada: James Tursa el 7 de Sept. de 2017
If you just want to plot a rotated moon phase, here is an approach using the "fill" command.
% ang = angle to rotate counter-clockwise (degrees)
% f = phase fraction (full moon = -1 <= f <= 1 = new moon)
function moonphaseplot(ang,f)
% Moon outer edge
a = 0:360;
xm = cosd(a);
ym = sind(a);
% Moon outer edge of lit portion
a = -90:90;
xe = cosd(a);
ye = sind(a);
% Moon terminator
a = 90:-1:-90;
xt = cosd(a)*f;
yt = sind(a);
% Rotate
R = [cosd(ang) -sind(ang);
sind(ang) cosd(ang)];
XY = R * [xm;ym];
xm = XY(1,:);
ym = XY(2,:);
XY = R * [xe xt;ye yt];
xet = XY(1,:);
yet = XY(2,:);
% Plot
figure;
hold on
z = 2;
fill([-z z z -z],[-z -z z z],'b'); % background blue sky
plot(2*z*rand(100,1)-z,2*z*rand(100,1)-z,'w.'); % background stars white
fill(xm,ym,'k'); % moon full disk black
fill(xet,yet,'w'); % moon lit portion white
axis square
axis off
title('Moon Phase')
end
For example:
>> moonphaseplot(135,-.5)
%

Walter Roberson
Walter Roberson el 14 de Oct. de 2011
For any one area that you want to shade, find the largest rectangle that will fit within it, and draw that rectangle. This will touch the perimeter of the area in at least two places, thus partitioning the original area in to a set of areas. For each area so produced, find and draw the largest rectangle in what remains, found what is left over, add it to the queue. Keep going this way until your spaces all happen to be filled completely by rectangles or your remaining spaces reach single pixels (in which case you fill them all with single-pixel rectangles.) You can do the shading by requesting in the rectangle() call that the rectangle be filled.
Are there easier methods to do the shading? Yes, but they don't involve using rectangles.
  6 comentarios
Jan
Jan el 14 de Oct. de 2011
Movida: Dyuman Joshi el 18 de Nov. de 2023
It would be easier to implement, if the moon is assumed to be a cube.

Iniciar sesión para comentar.

Categorías

Más información sobre Earth and Planetary Science en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by