Very Difficult MATLAB program I am trying to write.

조회 수: 8 (최근 30일)
Brian
Brian 2011년 10월 14일
댓글: Walter Roberson 2023년 11월 20일
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
Walter Roberson
Walter Roberson 2011년 10월 14일
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 2017년 9월 7일
@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.

댓글을 달려면 로그인하십시오.

답변 (2개)

James Tursa
James Tursa 2017년 9월 7일
편집: James Tursa 2017년 9월 7일
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 2011년 10월 14일
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
Jan
Jan 2011년 10월 14일
이동: Dyuman Joshi 2023년 11월 18일
It would be easier to implement, if the moon is assumed to be a cube.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Earth and Planetary Science에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by