@@ -68,6 +68,13 @@ DSO_STROKE = 0.5
68
68
# Utility functions
69
69
###########################################################################
70
70
71
+ def parse_width ( w )
72
+ # Parse a width specification into its numeric part and its units, if any
73
+ m = /^([\d .]+)(.*)$/ . match ( w )
74
+ abort "Width expression should be <num><units>" unless m
75
+ [ m [ 1 ] . to_f , m [ 2 ] ]
76
+ end
77
+
71
78
def g ( x )
72
79
# Convert a floating point number to a string, limiting the digits.
73
80
"%.2f" % x
@@ -88,9 +95,11 @@ def deg_to_rad(dec)
88
95
dec * Math ::PI /180
89
96
end
90
97
91
- def project ( ra , dec , phi1 , phi2 , ra0 , dec0 )
98
+ def project ( ra , dec , phi1 , phi2 , ra0 , dec0 , scale = Scale )
92
99
# Project ra, dec onto a flat map using standard parallels phi1 and phi2
93
- # and centered on ra0, dec0. All parameters are in radians.
100
+ # and centered on ra0, dec0. All parameters are in radians. The
101
+ # returned x and y are scaled so that the map is 700 pixels wide. This
102
+ # makes it easier to keep the line strokes an appropriate width.
94
103
95
104
# Normalize the cone/cylinder opposite ra0
96
105
ra += 2 *Math ::PI if ra0 -ra > Math ::PI
@@ -110,7 +119,7 @@ def project(ra, dec, phi1, phi2, ra0, dec0)
110
119
x = rho *Math . sin ( theta )
111
120
y = rho0 - rho *Math . cos ( theta )
112
121
end
113
- return Scale *x , -Scale *y
122
+ return scale *x , -scale *y
114
123
end
115
124
116
125
def parse_coord ( coord )
250
259
def draw_border_path ( pts )
251
260
# Draw a constellation border path.
252
261
puts %Q[<polyline points="#{ pts . map { |x | x . map { |y | g ( y ) } . join ( "," ) } . join ( " " ) } "
253
- style="fill:none;stroke:grey;stroke-width:0.5;stroke-dasharray:3 "/>]
262
+ style="fill:none;stroke:grey;stroke-width:0.5"/>]
254
263
end
255
264
256
265
def draw_grid_path ( pts )
385
394
def plot_border ( bounds )
386
395
# Print the map border.
387
396
xmin , xmax , ymin , ymax = bounds
388
- puts %Q[<rect x=#{ f ( xmin ) } y=#{ f ( ymin ) } width=#{ f ( xmax -xmin ) } height=#{ f ( ymax -ymin ) } stroke="black" stroke-width="1 " fill="none"/>]
397
+ puts %Q[<rect x=#{ f ( xmin ) } y=#{ f ( ymin ) } width=#{ f ( xmax -xmin ) } height=#{ f ( ymax -ymin ) } stroke="black" stroke-width="0.5 " fill="none"/>]
389
398
end
390
399
391
400
def plot_map_number ( bounds , map_number )
@@ -402,8 +411,8 @@ options = {}
402
411
OptionParser . new do |opts |
403
412
opts . banner = "Usage: test.rb [options]"
404
413
405
- opts . on ( "-a " , "--scale FACTOR " , Integer , "Scale factor " ) do |v |
406
- options [ :scale ] = v
414
+ opts . on ( "-w " , "--width " , String , "Width of image " ) do |v |
415
+ options [ :width ] = v
407
416
end
408
417
opts . on ( "-r" , "--margin PIXELS" , Integer , "Margin outside map" ) do |v |
409
418
options [ :margin ] = v
@@ -417,7 +426,7 @@ OptionParser.new do |opts|
417
426
opts . on ( "-l" , "--lr DDDD.D+DDDD" , String , "Lower-right coordinate" ) do |v |
418
427
options [ :lr ] = v
419
428
end
420
- opts . on ( "-s " , "--stars MAG" , Float , "Plot stars" ) do |v |
429
+ opts . on ( "-S " , "--stars MAG" , Float , "Plot stars" ) do |v |
421
430
options [ :stars ] = v
422
431
end
423
432
opts . on ( "-g" , "--grid" , "Plot grid" ) do |v |
@@ -435,20 +444,18 @@ OptionParser.new do |opts|
435
444
opts . on ( "-D" , "--dso MAG" , Float , "Plot deep sky objects" ) do |v |
436
445
options [ :dso ] = v
437
446
end
438
- opts . on ( "-c " , "--const" , "Plot constellation lines" ) do |v |
447
+ opts . on ( "-C " , "--const" , "Plot constellation lines" ) do |v |
439
448
options [ :const ] = v
440
449
end
441
- opts . on ( "-b " , "--border" , "Plot constellation borders" ) do |v |
450
+ opts . on ( "-B " , "--border" , "Plot constellation borders" ) do |v |
442
451
options [ :border ] = v
443
452
end
444
- opts . on ( "-w " , "--milkyway" , "Plot milky way contours" ) do |v |
453
+ opts . on ( "-W " , "--milkyway" , "Plot milky way contours" ) do |v |
445
454
options [ :milkyway ] = v
446
455
end
447
456
end . parse!
448
457
449
- # Fixme: we need a different solution than scale
450
- Scale = options [ :scale ] || 700
451
-
458
+ Width = options [ :width ] || "6in"
452
459
Margin = options [ :margin ] || 0
453
460
454
461
# Establish some globals to specify the map to be generated.
@@ -474,17 +481,22 @@ else
474
481
475
482
# Approximate the map center.
476
483
Ra0 = ( Ra1 +Ra2 ) /2
477
- Ra0_ha = ( ra1 + ra2 ) / 2
484
+ Ra0_ha = Ra0 * 24 / ( 2 * Math :: PI )
478
485
Dec0 = ( Dec1 +Dec2 ) /2
479
486
end
480
487
481
488
# Determine the coordinates of the map boundary.
489
+ xmin , ymin = project ( Ra1 , Dec1 , Phi1 , Phi2 , Ra0 , Dec0 , 1.0 )
490
+ xmax , ymax = project ( Ra2 , Dec2 , Phi1 , Phi2 , Ra0 , Dec0 , 1.0 )
491
+ Scale = 700.0 /( xmax -xmin )
482
492
xmin , ymin = project ( Ra1 , Dec1 , Phi1 , Phi2 , Ra0 , Dec0 )
483
493
xmax , ymax = project ( Ra2 , Dec2 , Phi1 , Phi2 , Ra0 , Dec0 )
484
494
bounds = [ xmin , xmax , ymin , ymax ]
495
+ amt , units = parse_width ( Width )
496
+ Height = ( amt *( ymax -ymin ) /( xmax -xmin ) ) . to_s + units
485
497
486
498
# Print the header material.
487
- puts %Q[<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 #{ g ( xmax -xmin +2 *Margin ) } #{ g ( ymax -ymin +2 *Margin ) } ">]
499
+ puts %Q[<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 #{ g ( xmax -xmin +2 *Margin ) } #{ g ( ymax -ymin +2 *Margin ) } " width=" #{ Width } " height=" #{ Height } " >]
488
500
puts %Q[<g transform="translate(#{ g ( -xmin +Margin ) } , #{ g ( -ymin +Margin ) } )">]
489
501
puts %Q[<clipPath id="CP">]
490
502
puts %Q[<rect x=#{ f ( xmin ) } y=#{ f ( ymin ) } width=#{ f ( xmax -xmin ) } height=#{ f ( ymax -ymin ) } stroke="black" stroke-width="1" fill="white"/>]
0 commit comments