Very Difficult MATLAB program I am trying to write.

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

Your link didn't make it. Maybe you should think about ellipses instead.
Brian
Brian 2011년 10월 14일
http://www.google.com/imgres?imgurl=http://www.usno.navy.mil/USNO/astronomical-applications/images_aa/Moon_phases.jpg&imgrefurl=http://www.usno.navy.mil/USNO/astronomical-applications/astronomical-information-center/phases-percent-moon&h=1890&w=1260&sz=264&tbnid=-rrOSpx00Ld5MM:&tbnh=92&tbnw=61&prev=/search%3Fq%3Dphases%2Bof%2Bmoon%26tbm%3Disch%26tbo%3Du&zoom=1&q=phases+of+moon&docid=5q8YlWvJ2WdNlM&hl=en&sa=X&ei=PJ6XTuuKG-nL0QH4r_2zBA&ved=0CEoQ9QEwAw&dur=2140
The function call to draw ellipses is the same as the function call to draw rectangles: both involve calls to rectangle(). And it is probably easy to figure out the space occupied by a rectangle than to figure out all the intersection points near a set of ellipses.
I was thinking of only one ellipse, placed at the center, with major axis the same as the moon and then changing the minor axis from 0 to the moon radius, and taking only half of it - if you can visualize that somewhat bad description. The other half would be then either be the lit moon, or black (the dark moon). I could be wrong though - I'm not sure of the exact equation of the shadow.
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.
@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일

0 개 추천

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

Brian
Brian 2011년 10월 14일
이동: Dyuman Joshi 2023년 11월 18일
If I want to use very thin rectangles to shade the moon, how would I go about doing this?
Walter Roberson
Walter Roberson 2011년 10월 14일
이동: Dyuman Joshi 2023년 11월 18일
In accordance with what I said above about doing rectangles, except that instead of finding the "largest rectangle that would fit within", you would find "the largest thin rectangle that would fit within" (for whatever you deem a "thin" rectangle to be.)
Figuring out where the boundary edge for the shading should be much more difficult than doing the shading.
Brian
Brian 2011년 10월 14일
이동: Dyuman Joshi 2023년 11월 18일
ok sorry, i will be more clear...i meant that i am prompting the user for a number "n" that will be the number of rectangles that are creating the shading, so it is like i am stacking very thin rectangles on top of each other (each rectangle will have height 2r/n)
Walter Roberson
Walter Roberson 2011년 10월 14일
이동: Dyuman Joshi 2023년 11월 18일
Either I do not understand or else that arrangement would lead to highly unrealistic shading.
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.

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

카테고리

도움말 센터File Exchange에서 Earth and Planetary Science에 대해 자세히 알아보기

질문:

2011년 10월 14일

댓글:

2023년 11월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by