The SunSphereImage Applet is displayed here if your browser supports Java. SunSphereImage requires complete Java 1.1 support. SunSphereImage displays an image of the earth showing the sunrise and sunset terminator. It uses your local timezone, which must have been set correctly, to approximate your local longitude and give the impression that you are looking down on the earth from above the equator. You can reposition the image by clicking or grabbing it with the mouse. Opt-clicking (Mac) or Alt-clicking (Windows), or Control-clicking displays the time of sunrise and sunset for the nearest city to the mouse.

Click the "spin" button (if visible) to rotate the globe continuously. You can also grab the globe with the mouse and spin it directly. You'll see that city lights "twinkle" because the transformation from the underlying map to the globe reveals different patterns of the yellow city color. You can spin the globe faster or slower (or in the wrong direction) by dragging it with the mouse.

Because rotating and spinning with latitude changes requires much more computation than longitude-only, you need to enable these features by clicking on the 'i' button or double-clicking near the globe image to display the option dialog. This dialog also lets you enable or disable the dynamic cloud display.

SunSphereImage is a large applet and takes a while to load and start running; give it time. The SunSphereImage Applet requires complete Java 1.1 support and does not run on some versions of Netscape Navigator on MacOS. Click here for a simpler applet that should work on all browsers that support Java.

Click Move the globe so the location you clicked is at the center.
Drag Rotate the globe to follow your movement. By default, this only modifies the longitude of the center point. Use the option dialog to enable both latitude and longitude dragging. Dragging the globe also adjusts the direction and speed of rotation if you enable spinning.
Alt-Click (Mac), Option-click (Windows)
or Control-click (any)
Locate the city nearest the location you clicked and displays its name and the time of sunrise and sunset. Not all cities have correct timezone information, so the sunrise/sunset time may be off by one hour if Daylight Savings Time is in effect.
Double-click near, but not
in the globe image.
Display the configuration dialog.

Jars Registered The original version of the SunSphereImage applet was "Rated Top 5% WebApplet" by JARS. This revision has not yet been rated.

If you find bugs in this program (or make improvements), please contact me.

Adding SunSphereImage to Your Home Page

You may use SunSphereImage in your personal, non-commercial, home page. In doing so, you understand that I make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any incidental or consequental damages in connection with or arising out of the use of the information or program. To add SunSphereImage, add the following HTML to your web page:
<applet
  codebase="http://www.shiggy.com/SunSphereImage"
  archive=SunSphereImage.jar
  code="org.minow.SunSphereImage.SunSphereImage.class"
  width=240
  height=340
>
<param name="bgcolor" value="#EEEEFF" >
The SunSphere Applet is displayed here if your browser supports Java. SunSphereImage requires complete Java 1.1 support.
</applet>
You may specify the following optional parameters.
bgcolor A value that matches the background color of your web page. A value of #000099 looks nice, for example.
fgcolor The desired text (foreground) color. This is really only useful if you also specify a background color.
image The name of the image file. The applet looks for the image file in your document folder (directory) and, if it is not in that folder, it looks in the folder containing the applet code archive.
autostart "true" to start spinning the globe when the applet starts.
cityfile The name of an XML formatted file that contains the names of all cities, their location, and timezones. The applet looks for the city file in your document folder (directory) and, if it is not in that folder, it looks in the folder containing the applet code archive.
cloudfile The name of an image file containing the latest cloud image. Do not specify to fetch the cloud image from the University of Wisconsin server. If set, an auxiliary process, such as a "crontab" script running on a Unix system, will provide a timely local copy of the University of Wisconsin file. See the cloud image description for more information.
getcloudimage "true" to fetch the current cloud image. See the cloud image description for more information.
showbuttons "true" to show the "spin" and "info" buttons (default). "false" to hide these buttons. If false, you can call up the configuration dialog by double-clicking near (but not in) the globe image..
showclock "true" to show the analog clock (default). False to hide the clock.
hinttime The number of seconds to show the user-interface hint (default 30). Set to zero to hide the hint at startup..
latitude The initial latitude of the center of the globe in fractional degrees. North is positive.
longitude The initial longitude of the center of the globe in fractional degrees. East is positive.
latitudespin The initial latitude spin (North/South). To enable latitude spins, both the enablelatitudespin and autostart parameters must be true. Latitude spins are computationally intensive.
longitudespin The initial longitude spin (East/West). Latitude spins are very fast to compute. The value should be negative to spin in the "natural" direction of the Earth's rotation.
enablelatitudespin True to enable spinning the globe in a North/South direction. this is computationally intensive. The autostart controls all spinning.
spininterval The time between each spin cycle in milliseconds..

The Cloud Display

If SunSphereImage runs as an application on a computer that is directly connected to the Internet, it can download an up-to-date satellite cloud image from a University of Wisconsin server. To access this server, you must either run SunSphereImage as an application from your local system or set your browser's Java security preferences to allow applets "unrestricted network access." Note that this will increase the risk that a rogue Java applet performs some unwanted action (it does not allow Java applets to read files on your local system, however).

As an alternative, you can specify a local file in the applet parameter list and provide an external mechanism, such as a "crontab" script, that maintains a timely image on your web server.

By default, the cloud image display feature is enabled if SunSphereImage runs as an application and disabled if it runs as an applet. You can explicitly enable or disable it using the option dialog or applet parameter list.

Creating the Sunrise Image

The image is a map of the world stored as a rectangular array of pixels. Technically, this is called a Plate Carrée or equirectangular projection. It is a poor choice for a map, but a good choice for the underlying image as it is exceedingly simple to convert between latitude/longitude and pixel coordinates. For example, if the image is 360 pixels wide, every pixel column represents a single degree of longitude.

To show twilight and night, the program shades the map by computing the altitude of the sun at every pixel. If the sun is below the horizon, the algorithm darkens the pixel. (This is, actually, slightly inaccurate: shading should begin when the sun is 20° above the horizon.)

SunriseFilter.java performs this computation once a minute using support functions in SunEphemeris.java. While the filter operation is moderately compute-intensive, the implementation uses several vectors to pre-compute most of the data and this is not a performance bottleneck.

Turning the Sunrise Image into a Globe

Before drawing the image on the display, it must be converted from the equirectangular form to a globe (a sphere projected onto the two-dimensional display). Since we want to be able to rotate and spin the image, this must be fast. To do this, SunSphereGlobeImage.java pre-computes the trignometric conversion by constructing two vectors with the conversion coefficients. Each element in these vectors corresponds to a single pixel in the sphere that will be displayed. One vector has the latitude in the original image that will be drawn on this pixel. The other vector has the adjustment to the original image longitude that depends on this latitude. The algorithm underlying this computation was defined in "Map Projections, a Working Manual". (Adapting this class to take advantage of Java3D support is beyond the scope of my interests.)

When these vectors have been computed, the program can rotate the image very quickly in the East to West direction, as it doesn't need to recompute the trignometric "sphere to circle" projection. Unfortunately, to rotate North or South, the vectors must be rebuilt whenever the latitude changes. This takes about ten times longer than a purely horizontal rotation. By default, the image can only be rotated horizontally: use the option dialog to override the default.

Spinning the Globular Image (Quickly)

SunSphereImageCanvas.java manages image drawing. This class also detects mouse clicks and dragging. When the mouse moves across the image, it revisits the trignometric functions to convert the mouse pixel coordinates to their corresponding latitude and longitude. As this changes, it rotates the globe as needed. If the mouse is moving when the user releases the button, the earth spins in the requested direction (and speed). To make the program run quickly, only longitude can be changed (but you can enable latitude movement using the option dialog.)

Converting Pixel Coordinates to Latitude and Longitude

In order to locate the mouse with respect to the underlying globe, the mouse's pixel coordinates are converted to latitude and longitude using the orthographic projection formula described by John P. Snyder in "Map Projections -- A Working Manual". Page 148-150:
pixel = mouse point Detemine the location of the mouse point with respect to the sphere. This value ranges from zero to the sphere diameter, with increasing values to the right and down.
x = (double) (pixel.x - sphereRadius); Convert the horizontal pixel coordinate to a value that ranges from (-radius) to (+radius) from left to right.
y = (double) (sphereRadius - pixel.y); Convert the vertical pixel coordinate to a value that ranges from (-radius) to (+radius) from bottom to top. Note that this is opposite the Java coordinate convention.
rho = sqrt((x * x) + (y * y)); Compute the length of the vector from the origin to the indicated point. If this is greater than the radius of the sphere, return an error. Alternatively, you can force the value to the radius. If rho is zero, the user clicked on the origin: return latitude 0.0, longitude 0.0 to avoid computing arctan(0.0 / 0.0) below.
C = arcsin(rho / sphereRadius);
latitude = arcsin((y * sin(C)) / rho);
longitude = arctan((x * sin(C)) / (rho * cos(C)));
Compute the latitude and longitude with respect to the origin. As noted above, the algorithm must detect a click on the origin to avoid dividing by zero.

Java Source Files

Click here for documentation on the Java classes and methods. The sources are distributed in the src.zip archive. SunSphereImage uses several additional files:
Earth.jpg
Earth.jpg is the image that underlies the spherical map of the earth. It was produced from a number of NASA satellite images by Geosphere Inc. Copyright © Geosphere Inc. Used by permission. Please contact Geosphere at geosphere@aol.com or see their web page at http://www.geosphere.net for information about this image or other Geosphere products. Please do not use this image without permission from Geosphere.
SunSphereImage.jar.
This archive contains the executable classes.
SunSphereImage.html
contains the web page source that displays the SunSphereImage applet.

References and Additional Information

Made with Macintosh SunSphere was created using MRJ Mac OS Runtime for Java.

Copyright © 1996-2000 Martin Minow. All Rights Reserved.

Permission to use, copy, modify, and redistribute this software and its documentation for personal, non-commercial use is hereby granted provided that this copyright notice and appropriate documentation appears in all copies. This software may not be distributed for fee or as part of commercial, "shareware," and/or not-for-profit endevors including, but not limited to, CD-ROM collections, online databases, and subscription services without specific license. The author makes no expressed or implied warranty of any kind and assumes no responsibility for errors or omissions. No liability is assumed for any incidental or consequental damages in connection with or arising out of the use of the information or program.