FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support inverted r axis range. · gnuplot/gnuplot-old@1c8b3b8 · GitHub

Repository navigation

Commit 1c8b3b8

Browse files
sfeam
committed
Support inverted r axis range.
'set rrange [90:0]' produces a projection celestial horizontal coordinates (altitude, azimuth)
1 parent ce6d5dd commit 1c8b3b8

13 files changed

Lines changed: 238 additions & 35 deletions

File tree

‎ChangeLog‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66
is printed whether or not the program is currently in polar mode.
77
Keywords for offset, font, etc as for the other axis label commands.
88

9+
* src/axis.c src/gadgets.c src/gadgets.h src/graphics.c src/mouse.c
10+
src/plot2d.c src/set.c docs/gnuplod.doc: Support inverted r axis range.
11+
rrange must be linear and have fixed max/min (no autoscaling).
12+
13+
Allows use of polar mode to display a projection of celestial horizontal
14+
coordinates (altitude + azimuth) with the zenith (altitude 90) at the
15+
center and the horizon (altitude 0) at the perimeter. Theta represents
16+
the azimuthal angle.
17+
18+
* demo/solar_path.dem demo/solar_params.dem demo/all.dem:
19+
Use inverted rrange to display solar path at a specific latitude in
20+
celestial horizontal coordinates.
21+
922
2017-01-08 Ethan A Merritt <merritt@u.washington.edu>
1023

1124
* src/axis.c (gen_tics) unset.c (unset_polar): Allow placement of tics

‎NEWS‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ Changes not in 5.0
2929
* NEW wxt supports printing on Windows
3030
* NEW dumb suports ANSI colors and filled polygons
3131
* NEW terminal sixelgd (sixel terminal graphics using gdlib)
32-
* NEW "set [m]ttics" controls placement of labels around perimeter of polar grid
3332
* NEW windows graph windows can be docked to the wgnuplot text window
33+
* NEW improveements, extensions, and bug fixes for polar graph mode
34+
* NEW "set [m]ttics" places labels around perimeter of polar grid
35+
* NEW "set rlabel" places a label above the r axis
36+
* NEW "set rrange [90:0]" plots in celestial horizontal coordinates
37+
* NEW "set border polar" uses border linetype for perimeter of polar plot
3438
* CHANGE Revise placement of axis labels in 3D plots
3539
* CHANGE Timestamp is now placed relative to page rather than plot boundary
3640
* CHANGE Track font/enhanced for key title separately from the key entries

‎demo/all.dem‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# $Id: all.dem,v 1.78 2017-01-04 01:00:23 sfeam Exp $
2+
# $Id: all.dem,v 1.79 2017-01-11 04:13:58 sfeam Exp $
33
#
44
# Executes all demos (OK, MOST demos) in this directory.
55
# This serves as a series of unit tests for non-interactive capabilities.
@@ -79,6 +79,10 @@ print "******************** file poldat.dem ********************"
7979
load "poldat.dem"
8080
reset
8181

82+
print "******************** file solar_path.dem ****************"
83+
load "solar_path.dem"
84+
reset
85+
8286
print "******************** file ttics.dem ********************"
8387
load "ttics.dem"
8488
reset

‎demo/solar_params.dem‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
# Calculate solar position in equitorial coordinates (ascension, declination)
3+
# then convert to horizontal coordinates (altitude, azimuth).
4+
# Parameters L, g, lambda, and eps are appoximated using values chosen
5+
# for accuracy in the era on either side of Jan 2000.
6+
#
7+
# Input:
8+
# Date - string with format "dd-mm-YYYY HH:MM"
9+
# Latitude - in degrees
10+
#
11+
# Output:
12+
# Function definitions
13+
# Azimuth(t) = Solar azimuth at time t
14+
# Altitude(t) = Solar altitude at time t
15+
# where t is time in seconds relative to local solar noon on Date.
16+
#
17+
# Local values:
18+
Minute = 60.
19+
Hour = 3600.
20+
Day = 86400.
21+
TimeFormat = "%d-%m-%Y %H:%M"
22+
phi = Latitude
23+
set angle degrees
24+
#
25+
# n = local time in days since noon on 1 Jan 2000
26+
# L = mean solar longitude in ecliptic coordinates
27+
# = 280.460° + 0.9856474° * n
28+
# g = orbital anomaly
29+
# = 357.528° + 0.9856003° * n
30+
# lamba = solar longitude
31+
# = L + 1.915° * sin(g) + 0.020° * sin(2g)
32+
# eps = obliquity of the ecliptic
33+
# = 23.439° - 0.0000004° * n
34+
35+
n = (strptime(TimeFormat, Date) - strptime(TimeFormat, "01-01-2000 12:00")) / Day
36+
37+
L = n * 0.9856474 + 280.460
38+
L = L - 360 * int(L / 360.)
39+
if (L < 0) { L += 360. }
40+
41+
g = n * 0.9856003 + 357.528
42+
g = g - 360 * int(g / 360.)
43+
if (g < 0) { g += 360. }
44+
45+
lambda = L + 1.915 * sin(g) + 0.020 * sin(2*g)
46+
47+
eps = 23.439 - n * 0.0000004
48+
49+
# Equatorial coordinates
50+
# RAsc = right ascension
51+
# Dec = declination
52+
53+
RAsc = atan2( cos(eps) * sin(lambda), cos(lambda) )
54+
Dec = asin( sin(eps) * sin(lambda) )
55+
56+
57+
# Horizontal coordinates
58+
59+
h(t) = 360. * t / Day
60+
Altitude(t) = asin( sin(Dec) * sin(phi) + cos(Dec) * cos(phi) * cos(h(t)) )
61+
62+
cosAzi(t) = ( sin(Dec) * sin(phi) - cos(Dec) * cos(h(t)) * sin(phi) ) \
63+
/ cos(Altitude(t))
64+
sinAzi(t) = ( -cos(Dec) * sin(h(t)) ) \
65+
/ cos(Altitude(t))
66+
Azimuth(t) = atan2( sinAzi(t), cosAzi(t) )
67+

‎demo/solar_path.dem‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#
2+
# Calculate solar path in horizontal coordinates (altitude, azimuth)
3+
# Use gnuplot's polar mode with inverted R range so that the horizon
4+
# (altitude 0°) is at the perimeter and altitude 90° is at the center.
5+
#
6+
7+
set label 1 at screen 0.02, 0.95 font ":Bold,10"
8+
set label 1 "Solar path at\nLatitude 47.47 N"
9+
set timestamp "Seattle - %d %b %Y"
10+
11+
# Set up equations for Azimuth(t) and Altitude(t)
12+
# as a function of t, the number of seconds before or after noon
13+
# (local standard time) on the day of interest at a particular latitude.
14+
# Here we calculate for Seattle (47.47 N -122.28 W)
15+
16+
Latitude = 47.47
17+
Date = "21-12-2016 12:00"
18+
call 'solar_params.dem'
19+
20+
array dummy[150]
21+
array winter_alt[150]
22+
array winter_azi[150]
23+
time = -12 * Hour
24+
do for [t = 1 : 150] {
25+
winter_alt[t] = Altitude(time)
26+
winter_azi[t] = Azimuth(time)
27+
dummy[t] = t
28+
time = time + 10 * Minute
29+
}
30+
31+
Date = "21-06-2016 12:00"
32+
call 'solar_params.dem'
33+
34+
array summer_alt[150]
35+
array summer_azi[150]
36+
time = -12 * Hour
37+
do for [t = 1 : 150] {
38+
summer_alt[t] = Altitude(time)
39+
summer_azi[t] = Azimuth(time)
40+
time = time + 10 * Minute
41+
}
42+
43+
Date = strftime(TimeFormat,time(0))
44+
call 'solar_params.dem'
45+
46+
array today_alt[150]
47+
array today_azi[150]
48+
time = -12 * Hour
49+
do for [t = 1 : 150] {
50+
today_alt[t] = Altitude(time)
51+
today_azi[t] = Azimuth(time)
52+
time = time + 10 * Minute
53+
}
54+
55+
#
56+
set angle degrees
57+
58+
set polar
59+
set grid polar
60+
unset xtics
61+
unset ytics
62+
unset border
63+
unset key
64+
set size square
65+
set rrange [90:0]
66+
67+
set ttics add ("N" 90, "E" 0, "S" -90, "W" 180) font ":Bold"
68+
set rtics format "%.0f°"
69+
set rtics 30
70+
set rlabel "Altitude" offset -2 font ":Bold"
71+
72+
# By convention North (azimuth 0°) should be at the top with angles
73+
# increasing clockwise, but gnuplot doesn't yet support anything but
74+
# theta=0 at the right and angles increasing counter-clockwise.
75+
# So we must manually label the angles and add an offset both to the
76+
# tic labels and to the plotted azimuthal angle.
77+
#
78+
# plot [t = -8*Hour : 8*Hour] '+' using (90-Azimuth(t)):(Altitude(t)) title "Winter Solstice" at end
79+
80+
plot dummy using (90 - winter_azi[$1]):(winter_alt[$1]) lw 2 title " Winter Solstice" at beg left, \
81+
dummy using (90 - summer_azi[$1]):(summer_alt[$1]) lw 2 title " Summer Solstice" at beg left, \
82+
dummy using (90 - today_azi[$1]):(today_alt[$1]) lw 2 title "Today " at end right
83+
84+
pause -1 "<cr> to continue"

‎docs/gnuplot.doc‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
C RCS $Id: gnuplot.doc,v 1.1042 2017-01-10 21:22:54 sfeam Exp $
1+
C RCS $Id: gnuplot.doc,v 1.1043 2017-01-11 04:13:59 sfeam Exp $
22
C
33
C Copyright (C) 1986 - 1993, 1998, 1999, 2000, 2001, 2004 Thomas Williams, Colin Kelley et al.
44
C
@@ -216,10 +216,14 @@ C
216216

217217
* New full-featured terminal driver for sixel graphics (see `sixelgd`).
218218

219-
* Polar grid elements (circles and radial lines) can be generated whether or
220-
not the program is in polar mode for the purpose of interpreting input
221-
coordinates. Tickmarks and labels around the perimeter of the polar grid
222-
are controlled by `set ttics`. See `ttics`.
219+
* Significant improvements and extensions to the polar coordinate system.
220+
Previous versions of gnuplot produced incorrect or unexpected results for
221+
out-of-range values of r and for rrange inverted (e.g. rrange [90:0]).
222+
Inverted rrange can now be used to generate plots in a celestial horizontal
223+
coordinates (center = zenith = altitude 90, perimeter = horizon = altitude 0).
224+
Polar grid elements (circles and radial lines) can now be generated whether or
225+
not the program is in polar mode. Tickmarks and labels around the perimeter
226+
of the polar grid are controlled by `set ttics`. See `ttics`.
223227

224228
* `windows` graph windows can be docked to the wgnuplot text window, which is
225229
especially useful with Windows in "tablet mode".

‎src/axis.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: axis.c,v 1.216 2017-01-08 04:41:22 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: axis.c,v 1.217 2017-01-11 04:13:59 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - axis.c */
@@ -1048,6 +1048,8 @@ gen_tics(struct axis *this, tic_callback callback)
10481048
if (nonlinear(this))
10491049
internal = eval_link_function(this->linked_to_primary, mark->position)
10501050
- eval_link_function(this->linked_to_primary, polar_shift);
1051+
else if (inverted_raxis)
1052+
internal = R_AXIS.set_min - mark->position;
10511053
else
10521054
internal = axis_log_value(this, mark->position)
10531055
- axis_log_value(this, polar_shift);
@@ -1403,8 +1405,11 @@ gen_tics(struct axis *this, tic_callback callback)
14031405
} else if (this->tictype == DT_DMS) {
14041406
gstrdms(label, this->ticfmt, (double)user);
14051407
} else if (this->index == POLAR_AXIS) {
1406-
internal = axis_log_value(this, tic)
1407-
- axis_log_value(this, R_AXIS.min);
1408+
if (inverted_raxis)
1409+
internal = R_AXIS.min - tic;
1410+
else
1411+
internal = axis_log_value(this, tic)
1412+
- axis_log_value(this, R_AXIS.min);
14081413
gprintf(label, sizeof(label), this->ticfmt, log10_base, tic);
14091414
} else if (this->index >= PARALLEL_AXES) {
14101415
/* FIXME: needed because ticfmt is not maintained for parallel axes */

‎src/gadgets.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: gadgets.c,v 1.133 2016-11-08 05:41:24 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: gadgets.c,v 1.134 2017-01-11 04:13:59 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - gadgets.c */
@@ -127,6 +127,7 @@ int timelabel_bottom = TRUE;
127127

128128
/* flag for polar mode */
129129
TBOOLEAN polar = FALSE;
130+
TBOOLEAN inverted_raxis = FALSE;
130131

131132
/* zero threshold, may _not_ be 0! */
132133
double zero = ZERO;

‎src/gadgets.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ extern text_label timelabel;
458458
extern int timelabel_bottom;
459459

460460
extern TBOOLEAN polar;
461+
extern TBOOLEAN inverted_raxis; /* true if R_AXIS.set_min > R_AXIS.set_max */
461462

462463
#define ZERO 1e-8 /* default for 'zero' set option */
463464
extern double zero; /* zero threshold, not 0! */

‎src/graphics.c‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef lint
2-
static char *RCSid() { return RCSid("$Id: graphics.c,v 1.539 2017-01-08 04:53:16 sfeam Exp $"); }
2+
static char *RCSid() { return RCSid("$Id: graphics.c,v 1.540 2017-01-11 04:13:59 sfeam Exp $"); }
33
#endif
44

55
/* GNUPLOT - graphics.c */
@@ -242,8 +242,8 @@ place_grid(int layer)
242242
if (R_AXIS.ticmode && (raxis || polar)) {
243243
/* Piggyback on the xtick2d_callback. Avoid a call to the full */
244244
/* axis_output_tics(), which wasn't really designed for this axis. */
245-
tic_start = map_y(0); /* Always equivalent to tics on phi=0 axis */
246-
tic_mirror = tic_start; /* tic extends on both sides of phi=0 */
245+
tic_start = map_y(0); /* Always equivalent to tics on theta=0 axis */
246+
tic_mirror = tic_start; /* tic extends on both sides of theta=0 */
247247
tic_text = tic_start - t->v_char;
248248
rotate_tics = R_AXIS.tic_rotate;
249249
if (rotate_tics == 0)
@@ -3400,14 +3400,15 @@ xtick2d_callback(
34003400
if (this_axis->index == POLAR_AXIS) {
34013401
double x = place, y = 0, s = sin(0.1), c = cos(0.1);
34023402
int i;
3403-
int ogx = map_x(x);
3404-
int ogy = map_y(0);
3405-
int gx, gy;
3403+
int ogx, ogy, gx, gy;
34063404

34073405
if (place > largest_polar_circle)
34083406
largest_polar_circle = place;
34093407
else if (-place > largest_polar_circle)
34103408
largest_polar_circle = -place;
3409+
3410+
ogx = map_x(x);
3411+
ogy = map_y(0);
34113412
for (i = 1; i <= 63 /* 2pi/0.1 */ ; ++i) {
34123413
{
34133414
/* cos(t+dt) = cos(t)cos(dt)-sin(t)cos(dt) */
@@ -3941,14 +3942,19 @@ place_raxis()
39413942

39423943
x0 = map_x(0);
39433944
y0 = map_y(0);
3944-
rightend = (R_AXIS.autoscale & AUTOSCALE_MAX) ? R_AXIS.max : R_AXIS.set_max;
3945-
xend = map_x( AXIS_LOG_VALUE(POLAR_AXIS,rightend)
3946-
- AXIS_LOG_VALUE(POLAR_AXIS,R_AXIS.set_min));
3945+
if (inverted_raxis) {
3946+
xend = map_x(R_AXIS.set_min);
3947+
} else {
3948+
rightend = (R_AXIS.autoscale & AUTOSCALE_MAX) ? R_AXIS.max : R_AXIS.set_max;
3949+
xend = map_x( AXIS_LOG_VALUE(POLAR_AXIS,rightend)
3950+
- AXIS_LOG_VALUE(POLAR_AXIS,R_AXIS.set_min));
3951+
}
39473952
yend = y0;
39483953
term_apply_lp_properties(&border_lp);
39493954
draw_clip_line(x0,y0,xend,yend);
39503955

39513956
#ifdef EAM_OBJECTS
3957+
if (!inverted_raxis)
39523958
if (!(R_AXIS.autoscale & AUTOSCALE_MIN) && R_AXIS.set_min != 0)
39533959
place_objects( &raxis_circle, LAYER_FRONT, 2);
39543960
#endif

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL