The purpose of this tutorial is to illustrate how to draw a sphere using HoloDraw, and, by extension, how to plot any curved line or surface which is wrapped about a common center point. HoloDraw has several programs that you can use in combination to produce the shapes and effects you want. This illustrates, step by step, some of the things you might need to do as you plan and construct your drawing.
Our goal here is to draw a sphere composed of circular latitude and longitude lines. In practical application this sphere might represent, say, the Earth, and you might want to plot your data somewhere within or on the sphere. But first, you want a sphere.
For your drawings, you get to decide what you want. For example, how often do you want the latitude and longitude lines? What color should they be? For this example I decided I want North-South lines in green, every 30 degrees around the sphere. For my East-West lines I want them in blue and every 45 degrees.
Plan your drawing as if it were a flat rectangular map |
Since this drawing will ultimately become a sphere, the X and Y dimensions are specified in degrees. The Z dimension, which is used for the radius of the sphere, and possibly for plotting your data in the sphere, is up to you -- it could be kilometers, miles, inches, whatever makes sense for your project. So I want blue East-West lines at 0 degrees, 45 degrees, and -45 degrees, and green North-South lines every 30 degrees. I've decided I want my sphere to have a radius of 5000 units. Here is a HoloDraw input file that specifies those lines:
# this illustrates how to draw a sphere using HoloDraw # the X and Y values are degrees around the sphere # and the Z value is the sphere's radius # let's make some East-West lines in blue color=0 0 1 # draw a line around the sphere's equator # X will go from 0 to 360 degrees # Y will be 0 since this is the equator # Z will be 5000, the radius of our sphere line: 0 0 5000, 360 0 5000 # how about another line at Y=+45 and Y=-45 line: 0 45 5000, 360 45 5000 line: 0 -45 5000, 360 -45 5000 # next, our North-South lines should be green color=0 1 0 # draw a line from North pole (90 degrees) to South pole (-90) at X=0 line: 0 90 5000, 0 -90 5000 # and again halfway around the sphere, at X=180 line: 180 90 5000, 180 -90 5000 # while we're at it, make more vertical lines every 30 degrees line: 30 90 5000, 30 -90 5000 line: 60 90 5000, 60 -90 5000 line: 90 90 5000, 90 -90 5000 line: 120 90 5000, 120 -90 5000 line: 150 90 5000, 150 -90 5000 # and on past the 180 degree line we already drew line: 210 90 5000, 210 -90 5000 line: 240 90 5000, 240 -90 5000 line: 270 90 5000, 270 -90 5000 line: 300 90 5000, 300 -90 5000 line: 330 90 5000, 330 -90 5000 # don't need a line at 360 degrees because that is the same as 0 degrees |
Here's a Unix shell script to turn that drawfile into an image:
#!/bin/sh # filename: sphere.sh # author: Marvin Simkin # date: 2004-02-16 # purpose: demonstrate how to draw a simple sphere # -------------------------------------------------------------------------- # this shows the lines that are drawn, # but the resulting shape is flat not round drawwrl.pl < sphere.draw > flatgrid.wrl |
Now, open flatgrid.wrl in your VRML viewer. Depending on which program you use, the image may not appear in view. You may be "looking" the opposite direction, or you may be too close or too far away. If you use Cortona, it has a handy "fit" button in the lower right corner of the screen that will bring your drawing to the center of your screen, sized so that it fills the window.
Eventually you should see something like this:
You can use your viewer's controls to rotate and zoom and otherwise fly around in your image,
but it will not have any depth to it because everything was plotted all at the same Z-value of 5000.
In other words, at this point the image appears completely flat or two-dimensional.
Wrap the flat drawing around some center to make a sphere |
Even though the previous drawing looked perfectly flat, all the lines were at Z=5000. When we turn it into a sphere, this Z value becomes the radius. In other words, we will draw a sphere with a radius of 5000 whatevers. To do this, we use the same input file as before, but this time we pass it through the drawball.pl program.
Before we can do that, however, we need to consider a little bit about how curves are drawn on a computer. Typically a curve is plotted as a series of very short straight lines. The shorter they are, the more lines it will take to draw a complete circle. If you make a lot of really short lines, your VRML file will be huge and it will take a long time to process. If you make only a few lines that are too long or coarse, people will be able to see "kinks" when your lines bend every now and then.
So as you weigh the tradeoffs you need to consider your ultimate purpose and audience for the drawing. If you are making a magazine cover, you can probably afford to devote a lot of disk space and processing time to make the most detailed image you possibly can. After all, your audience will be looking at hardcopy which will be visible to them with no delay whatsoever. On the other hand, if you plan a live presentation in which you fly through a complicated world with lots of objects, you want your computer to refresh the screen as fast as possible. In this case you should keep your drawings as coarse as you can.
I usually find that while I am developing an image, coarser curves process faster allowing me to have a more rapid change-process-test cycle. But once things are starting to look pretty good, I go back and make finer curves consisting of more, shorter lines.
Does this mean I have to go back to my original input file, delete all the long lines, and hand-enter a bunch of new shorter lines? No! HoloDraw will make short lines for me, using my longer lines as input. The program that does this is drawchop.pl. All I have to do is tell drawchop.pl how often the long lines should be chopped into shorter ones.
For the purposes of this example, my North-South lines occur every 30 degrees, so I will chop my East-West lines every 30 degrees. The command drawchop.pl x=30+30 y=30+30 means to chop any line where it crosses the value X=30 and also every 30 degrees thereafter (e.g. 60, 90, 120...). Also, I am chopping Y lines every 30 degrees as well.
Here's a Unix shell script with commands added to turn that drawfile into a spherical image.
#!/bin/sh # filename: sphere.sh # author: Marvin Simkin # date: 2004-02-16 # purpose: demonstrate how to draw a simple sphere # -------------------------------------------------------------------------- # this shows the lines that are drawn, # but the resulting shape is flat not round drawwrl.pl < sphere.draw > flatgrid.wrl # -------------------------------------------------------------------------- # this takes the previous flat diagram # and wraps it into a ball # first we have to "chop" the long straight lines # into little short ones, # so that they can be wrapped around a globe. # The more often you chop, the smoother the lines, but the bigger your files. # If you chop too often, it can take a very long time to process. # This chops lines very coarsely (so you can see it) every 30 degrees # in the X and Y dimensions, # but there is no need to chop in the Z dimension. drawchop.pl x=30+30 y=30+30 < sphere.draw | # this does the conversion from spherical coordinates to cartesian drawball.pl | # and produce a VRML file we can view drawwrl.pl > ballgrid.wrl |
Open
ballgrid.wrl
in your VRML viewer and notice how the straight lines from before
are now bent every 30 degrees to form a rough sphere:
The green North-South lines now converge at the North and South poles,
and the blue East-West lines occur at the equator (Y=0)
as well as halfway up (Y=45 degrees) and down (Y=-45).
Because the lines are only chopped once every 30 degrees,
you can clearly see the relatively long straight lines
connected by sharp bends.
We'll fix that later by chopping the lines more often making a smoother curve.
But first, wouldn't it be nice to label our X and Y axes for reference?
Add an annotated bounding box to the flat grid |
HoloDraw includes a program, drawbbox.pl, that will automatically create an annotated bounding box around your drawing. You may not always like what it does, but don't worry, there are ways to gain more control over it as we go along. For now, we'll just take what it gives us.
Forget the sphere for a moment and let's go back to our original, flat drawing. We want a bounding box, which will label the X and Y coordinates of our grid. And let's make it red, so it will stand out from the green and blue lines of our drawing.
Here's a Unix shell script with commands added to create a red bounding box.
#!/bin/sh # filename: sphere.sh # author: Marvin Simkin # date: 2004-02-16 # purpose: demonstrate how to draw a simple sphere # -------------------------------------------------------------------------- # this shows the lines that are drawn, # but the resulting shape is flat not round drawwrl.pl < sphere.draw > flatgrid.wrl # -------------------------------------------------------------------------- # this takes the previous flat diagram # and wraps it into a ball # first we have to "chop" the long straight lines # into little short ones, # so that they can be wrapped around a globe. # The more often you chop, the smoother the lines, but the bigger your files. # If you chop too often, it can take a very long time to process. # This chops lines very coarsely (so you can see it) every 30 degrees # in the X and Y dimensions, # but there is no need to chop in the Z dimension. drawchop.pl x=30+30 y=30+30 < sphere.draw | # this does the conversion from spherical coordinates to cartesian drawball.pl | # and produce a VRML file we can view drawwrl.pl > ballgrid.wrl # -------------------------------------------------------------------------- # here is our original flat grid, but with an annotated "bounding box" # so that the X and Y dimensions will have labels # to help us see what's where # First, make the bounding box red, so it will stand out. echo 'color=1 0 0' > boundbox.draw # Next, generate a default bounding box and write it to the same file. # discard color from sphere.draw so it does not override what we set above grep -v 'color *=' < sphere.draw | drawbbox.pl >> boundbox.draw # Take both the original drawing, and the bounding box, # and make them into a single VRML file. cat sphere.draw boundbox.draw | drawwrl.pl > flatbbox.wrl |
The (possibly unexpected) thing to notice here is that drawbbox.pl is making a second, entirely separate drawing consisting of the lines and numbers that make up the bounding box. It reads the entire sphere.draw file for one purpose only: to find the minimum and maximum points in the X, Y and Z dimensions. (This implies that you can generate any size box you want, with annotation and tickmarks, simply by feeding drawbbox.pl two points: your minimum X Y and Z, and your maximum.) It then computes and plots a box around those extreme points, with periodic tickmarks and annotations. In this case, drawbbox.pl has decided to give us tickmarks and annotations every 60 degrees.
The final step, then, is to
combine
the original drawing with its bounding box
and put them both into one VRML file,
flatbbox.wrl.
Wrap it into a ball again |
Hopefully this step won't come as much of a surprise. Once again, we need to take that flat drawing -- both the original grid file and the new bounding box -- chop them every 30 degrees, and send them to drawball.pl to make us a nice annotated sphere.
The new lines added to the end of the script will make an annotated globe.
#!/bin/sh
# filename: sphere.sh
# author: Marvin Simkin
# date: 2004-02-16
# purpose: demonstrate how to draw a simple sphere
# --------------------------------------------------------------------------
# this shows the lines that are drawn,
# but the resulting shape is flat not round
drawwrl.pl < sphere.draw > flatgrid.wrl
# --------------------------------------------------------------------------
# this takes the previous flat diagram
# and wraps it into a ball
# first we have to "chop" the long straight lines
# into little short ones,
# so that they can be wrapped around a globe.
# The more often you chop, the smoother the lines, but the bigger your files.
# If you chop too often, it can take a very long time to process.
# This chops lines very coarsely (so you can see it) every 30 degrees
# in the X and Y dimensions,
# but there is no need to chop in the Z dimension.
drawchop.pl x=30+30 y=30+30 < sphere.draw |
# this does the conversion from spherical coordinates to cartesian
drawball.pl |
# and produce a VRML file we can view
drawwrl.pl > ballgrid.wrl
# --------------------------------------------------------------------------
# here is our original flat grid, but with an annotated "bounding box"
# so that the X and Y dimensions will have labels
# to help us see what's where
# First, make the bounding box red, so it will stand out.
echo 'color=1 0 0' > boundbox.draw
# Next, generate a default bounding box and write it to the same file.
# discard color from sphere.draw so it does not override what we set above
grep -v 'color *=' < sphere.draw |
drawbbox.pl >> boundbox.draw
# Take both the original drawing, and the bounding box,
# and make them into a single VRML file.
cat sphere.draw boundbox.draw |
drawwrl.pl > flatbbox.wrl
# --------------------------------------------------------------------------
# the same thing but rendered as a sphere instead of flat
cat sphere.draw boundbox.draw |
drawchop.pl x=30+30 y=30+30 |
# this does the conversion from spherical coordinates to cartesian
drawball.pl > ballbbox.draw
# The previous drawbbox.pl chose a default speed based on flat geometry
# but that is not fast enough for a sphere.
# Discard the old value and generate a better one from the sphere file.
grep -v speed < ballbbox.draw |
drawbbox.pl |
grep speed >> ballbbox.draw
# and produce a VRML file we can view
drawwrl.pl < ballbbox.draw > ballbbox.wrl
|
So I lied; maybe there's a surprise after all.
In the flat grid, all the X-dimension labels were along the bottom of the drawing.
But when we turn that into a sphere,
every one of those labels converge at the South pole.
The result is a nasty cluster of useless X-labels all in pretty much the same place.
Don't worry -- this can be fixed --
but it is beyond the scope of this particular tutorial.
Hint: think about where you would have to put the X-labels on the
flat
drawing,
in order to have them come out where you want them in the final sphere drawing.
Make the curves smoother |
Now that the drawing is just the way we want it (pretend with me, OK?) let's chop the lines a little more often so that our circles really look round.
Now that the script is complete, you can download a copy of it here.
#!/bin/sh
# filename: sphere.sh
# author: Marvin Simkin
# date: 2004-02-16
# purpose: demonstrate how to draw a simple sphere
# --------------------------------------------------------------------------
# this shows the lines that are drawn,
# but the resulting shape is flat not round
drawwrl.pl < sphere.draw > flatgrid.wrl
# --------------------------------------------------------------------------
# this takes the previous flat diagram
# and wraps it into a ball
# first we have to "chop" the long straight lines
# into little short ones,
# so that they can be wrapped around a globe.
# The more often you chop, the smoother the lines, but the bigger your files.
# If you chop too often, it can take a very long time to process.
# This chops lines very coarsely (so you can see it) every 30 degrees
# in the X and Y dimensions,
# but there is no need to chop in the Z dimension.
drawchop.pl x=30+30 y=30+30 < sphere.draw |
# this does the conversion from spherical coordinates to cartesian
drawball.pl |
# and produce a VRML file we can view
drawwrl.pl > ballgrid.wrl
# --------------------------------------------------------------------------
# here is our original flat grid, but with an annotated "bounding box"
# so that the X and Y dimensions will have labels
# to help us see what's where
# First, make the bounding box red, so it will stand out.
echo 'color=1 0 0' > boundbox.draw
# Next, generate a default bounding box and write it to the same file.
# discard color from sphere.draw so it does not override what we set above
grep -v 'color *=' < sphere.draw |
drawbbox.pl >> boundbox.draw
# Take both the original drawing, and the bounding box,
# and make them into a single VRML file.
cat sphere.draw boundbox.draw |
drawwrl.pl > flatbbox.wrl
# --------------------------------------------------------------------------
# the same thing but rendered as a sphere instead of flat
cat sphere.draw boundbox.draw |
drawchop.pl x=30+30 y=30+30 |
# this does the conversion from spherical coordinates to cartesian
drawball.pl > ballbbox.draw
# The previous drawbbox.pl chose a default speed based on flat geometry
# but that is not fast enough for a sphere.
# Discard the old value and generate a better one from the sphere file.
grep -v speed < ballbbox.draw |
drawbbox.pl |
grep speed >> ballbbox.draw
# and produce a VRML file we can view
drawwrl.pl < ballbbox.draw > ballbbox.wrl
# --------------------------------------------------------------------------
# this time it is chopped much more often to see the difference
cat sphere.draw boundbox.draw |
drawchop.pl x=5+5 y=5+5 |
# this does the conversion from spherical coordinates to cartesian
drawball.pl > ballx5y5.draw
# The previous drawbbox.pl chose a default speed based on flat geometry
# but that is not fast enough for a sphere.
# Discard the old value and generate a better one from the sphere file.
grep -v speed < ballx5y5.draw |
drawbbox.pl |
grep speed >> ballx5y5.draw
# and produce a VRML file we can view
drawwrl.pl < ballx5y5.draw > ballx5y5.wrl
|
The only difference between
ballbbox.wrl
and
ballx5y5.wrl
is that the lines are chopped every 5 degrees instead of every 30.
Notice that this simple change makes the VRML file
3 times bigger!
Use
drawchop.pl
with care or your more complex drawings will turn into monsters that take forever to process.
The final version of the script, above, looks pretty complicated. But note that it has a lot of comments. Also, it created not only the final version of the image but all the intermediate illustrations as well. Once you really know what you want to do, you can simplify it down to something like this:
#!/bin/sh
echo 'color=1 0 0' > boundbox.draw
grep -v 'color *=' < sphere.draw |
drawbbox.pl >> boundbox.draw
cat sphere.draw boundbox.draw |
drawchop.pl x=5+5 y=5+5 |
drawball.pl > ballx5y5.draw
grep -v speed < ballx5y5.draw |
drawbbox.pl |
grep speed >> ballx5y5.draw
drawwrl.pl < ballx5y5.draw > ballx5y5.wrl
|
That's really all there is to it! The above script creates the exact same VRML file as the previous, longer one.
|
|
|