Sample Supermongo Macros
fig01
#
# Astronomy 505: Homework #3, Problem 1 (Ideal Ball-and-String Pendulum)
# 1 September, 2002
# Nicole P. Vogt
#
# This macro creates a diagram of a pendulum of length l which is held such
# that the string is horizontal (ready to drop). There are four physical
# elements:
#
# the ball of the pendulum
# the string of the pendulum, of length l (runs to center of ball)
# the base point where the pendulum is secured, around which it rotates
# a nail, located a distance d = 0.6 x l below the base point
#
# The path of the ball is traced out. It falls in a circular arc of radius
# l for 90 degrees, and then the string catches on the nail. The ball then
# traces out a second arc of radius (l - d), for an additional 155 degrees.
#
# The nail and the lengths l and d are labeled, and a dashed vertical line
# runs from the base point through the nail and down to the edge of the
# figure. The ball, base point, and nail are filled with colour.
#
# n.b. The length l is written as R within the macro, for ease of reading.
#
macro read fig01.sm # read macros into memory; then type
# fig01 on sm command line to draw figure
#dev postencap :SY :OFfig01.eps # comment this line out to draw on screen
# rather than writing postscript to /tmp
#
# Set up figure.
#
era
ctype black ptype 20 3 expand 0.901 ltype 0 # initialize drawing format
set R = 100 # length of string
set d = R * 0.6 # distance from base to nail
set w = R / 15 # width of pendulum ball
lim $(-1.15*R) $(0.50*R) $(-1.15*R) $(0.50*R) # local coordinate limits -
# keep figure a square, so
# that circles are not oval
#
# Draw arc of path of pendulum ball, starting at edge of ball.
#
ltype 1 # dotted lines
set r0 = 180 + 180/pi * atan(w/R) # find edge of ball
draw_circ 0 0 $(R) $(r0) 270 # arc of radius R
draw_circ 0 $(-d) $(R-d) 270 425 # arc of radius (R - d)
relocate 0 0 draw 0 $(-1.15*R) # line from base through nail
#
# Draw labels and string
#
ltype 0 # solid lines
relocate 0 0 draw $(-R+w) 0 # string to edge of ball
relocate 5 0 draw 15 0 # label string (ends)
relocate 5 $(-d) draw 15 $(-d)
relocate 0 10 draw 0 20 # label nail position (ends)
relocate $(-R) 10 draw $(-R) 20
#
# Draw ball (fill with yellow, edge with black).
#
set a = 0, 2.1*pi, 0.01 # use angular variable to
set x = -R + cos(a) * w # define x and y coordinates
set y = 0 + sin(a) * w
ctype yellow angle 45 shade 100 x y # fill with yellow
ctype black angle 0 connect x y # edge with black
#
# Draw base point (fill with blue, edge with black).
#
set x = cos(a) * w / 6
set y = sin(a) * w / 6
ctype blue angle 45 shade 100 x y
ctype black angle 0
connect x y
#
# Draw nail (fill with blue, edge with black).
#
set x = cos(a) * w / 3
set y = -d + sin(a) * w / 3
ctype blue angle 45 shade 100 x y
ctype black angle 0
connect x y
#
# Label figure elements.
#
expand 1.501 label_arrow $(-R) 15 0 15 15 "l"
expand 1.501 label_arrow2 10 $(-d) 10 0 15 "d"
expand 1.501 relocate -5 $(-d) putlabel 4 Nail
#
# Return to screen display, if creating postscript figure.
#
dev x11
draw_circ 5
#
# Draw circle at ($1,$2) of radius ($3) between angles ($4) to ($5),
# input in degrees.
#
set i = $4*pi/180, $5*pi/180, 0.001 # supermongo works in radians
set x = $1 + $3*cos(i)
set y = $2 + $3*sin(i)
connect x y
draw_circle 8
#
# Draw circle at ($1,$2) of radius ($3) between angles ($4) to ($5),
# input in degrees. Align label at midpoint of arc, with offsets
# ($6,$7) and content ($8).
#
draw_circ $1 $2 $3 $4 $5
relocate $(x[dimen(x)/2] + $6) $(y[dimen(y)/2] + $7)
putlabel 5 $8
label_arrow 6
#
# Draw a two-headed horizontal arrow from ($1,$2) to ($3,$4).
# Form a gap at the center of width ($5) to place label ($6).
#
set _x1 = ($1 + $3)/2
set _y1 = ($2 + $4)/2
relocate $(_x1) $(_y1) putlabel 5 $6
expand 0.601
draw_arrow $(($1 + $3)/2 - $5/2) $(_y1) $1 $2
draw_arrow $(($1 + $3)/2 + $5/2) $(_y1) $3 $4
label_arrow2 6
#
# Draw a two-headed vertical arrow from ($1,$2) to ($3,$4).
# Form a gap at the center of width ($5) to place label ($6).
#
set _x1 = ($1 + $3)/2
set _y1 = ($2 + $4)/2
relocate $(_x1) $(_y1) putlabel 5 $6
expand 0.601
draw_arrow $(_x1) $(($2 + $4)/2 - $5/2) $1 $2
draw_arrow $(_x1) $(($2 + $4)/2 + $5/2) $3 $4