plplot 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+ $-w = true if $0 == __FILE__
3
+
4
+ require 'rubygems'
5
+ require 'plplot'
6
+ include PLplot
7
+
8
+ # Filling and clipping polygons.
9
+
10
+ #--------------------------------------------------------------------------
11
+ # Test program for filling polygons and proper clipping
12
+ #--------------------------------------------------------------------------
13
+
14
+ # Parse and process command line arguments
15
+
16
+ PLOptionParser.parse!
17
+
18
+ # Initialize plplot
19
+
20
+ plssub(3, 3)
21
+ plinit
22
+
23
+ xextreme = [
24
+ [-120.0, 120.0],
25
+ [-120.0, 120.0],
26
+ [-120.0, 120.0],
27
+ [ -80.0, 80.0],
28
+ [-220.0, -120.0],
29
+ [- 20.0, 20.0],
30
+ [ -20.0, 20.0],
31
+ [ -80.0, 80.0],
32
+ [ 20.0, 120.0]
33
+ ]
34
+
35
+ yextreme = [
36
+ [-120.0, 120.0],
37
+ [ 20.0, 120.0],
38
+ [ -20.0, 120.0],
39
+ [ -20.0, 120.0],
40
+ [-120.0, 120.0],
41
+ [-120.0, 120.0],
42
+ [ -20.0, 20.0],
43
+ [ -80.0, 80.0],
44
+ [-120.0, 120.0],
45
+ ]
46
+
47
+
48
+ 2.times do |k|
49
+ 4.times do |j|
50
+ x0 = []
51
+ y0 = []
52
+ if (j == 0)
53
+ # Polygon 1: a diamond
54
+ x0[0] = 0; y0[0] = -100
55
+ x0[1] = -100; y0[1] = 0
56
+ x0[2] = 0; y0[2] = 100
57
+ x0[3] = 100; y0[3] = 0
58
+ elsif (j == 1)
59
+ # Polygon 1: a diamond - reverse direction
60
+ x0[3] = 0; y0[3] = -100
61
+ x0[2] = -100; y0[2] = 0
62
+ x0[1] = 0; y0[1] = 100
63
+ x0[0] = 100; y0[0] = 0
64
+ npts = 4
65
+ elsif (j == 2)
66
+ # Polygon 2: a square with punctures
67
+ x0[0] = -100; y0[0] = -100
68
+ x0[1] = -100; y0[1] = -80
69
+ x0[2] = 80; y0[2] = 0
70
+ x0[3] = -100; y0[3] = 80
71
+ x0[4] = -100; y0[4] = 100
72
+ x0[5] = -80; y0[5] = 100
73
+ x0[6] = 0; y0[6] = 80
74
+ x0[7] = 80; y0[7] = 100
75
+ x0[8] = 100; y0[8] = 100
76
+ x0[9] = 100; y0[9] = -100
77
+ elsif (j == 3)
78
+ # Polygon 2: a square with punctures - reversed direction
79
+ x0[9] = -100; y0[9] = -100
80
+ x0[8] = -100; y0[8] = -80
81
+ x0[7] = 80; y0[7] = 0
82
+ x0[6] = -100; y0[6] = 80
83
+ x0[5] = -100; y0[5] = 100
84
+ x0[4] = -80; y0[4] = 100
85
+ x0[3] = 0; y0[3] = 80
86
+ x0[2] = 80; y0[2] = 100
87
+ x0[1] = 100; y0[1] = 100
88
+ x0[0] = 100; y0[0] = -100
89
+ end
90
+
91
+ xextreme.each_index do |i|
92
+ pladv(0)
93
+ plvsta
94
+ plwind(xextreme[i][0], xextreme[i][1], yextreme[i][0], yextreme[i][1])
95
+
96
+ plcol0(2)
97
+ plbox("bc", 1.0, 0, "bcnv", 10.0, 0)
98
+ plcol0(1)
99
+ plpsty(0)
100
+ if (k == 0)
101
+ plfill(x0, y0)
102
+ else
103
+ plgradient(x0, y0, 45)
104
+ end
105
+ plcol0(2)
106
+ pllsty(1)
107
+ plline(x0, y0)
108
+ end
109
+ end
110
+ end
111
+
112
+ # Don't forget to call plend to finish off!
113
+
114
+ plend
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ $-w = true if $0 == __FILE__
4
+
5
+ require 'rubygems'
6
+ require 'plplot'
7
+ include PLplot
8
+ include Math
9
+
10
+ # Multi-lingual version of the first page of example 4.
11
+ #
12
+ # Copyright (C) 2006 Alan Irwin
13
+ # Copyright (C) 2006 Andrew Ross
14
+ #
15
+ # Thanks to the following for providing translated strings for this example:
16
+ # Valery Pipin (Russian)
17
+ #
18
+ # This file is part of PLplot.
19
+ #
20
+ # PLplot is free software; you can redistribute it and/or modify
21
+ # it under the terms of the GNU General Library Public License as published
22
+ # by the Free Software Foundation; either version 2 of the License, or
23
+ # (at your option) any later version.
24
+ #
25
+ # PLplot is distributed in the hope that it will be useful,
26
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
+ # GNU Library General Public License for more details.
29
+ #
30
+ # You should have received a copy of the GNU Library General Public License
31
+ # along with PLplot; if not, write to the Free Software
32
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33
+
34
+ # This example designed just for devices (e.g., psttfc and the
35
+ # cairo-related devices) that use the pango and fontconfig libraries. The
36
+ # best choice of glyph is selected by fontconfig and automatically rendered
37
+ # by pango in way that is sensitive to complex text layout (CTL) language
38
+ # issues for each unicode character in this example. Of course, you must
39
+ # have the appropriate TrueType fonts installed to have access to all the
40
+ # required glyphs.
41
+ #
42
+ # Translation instructions: The strings to be translated are given by
43
+ # x_label, y_label, alty_label, title_label, and line_label below. The
44
+ # encoding used must be UTF-8.
45
+ #
46
+ # The following strings to be translated involve some scientific/mathematical
47
+ # jargon which is now discussed further to help translators.
48
+ #
49
+ # (1) dB is a decibel unit, see http://en.wikipedia.org/wiki/Decibel .
50
+ # (2) degrees is an angular measure, see
51
+ # http://en.wikipedia.org/wiki/Degree_(angle) .
52
+ # (3) low-pass filter is one that transmits (passes) low frequencies.
53
+ # (4) pole is in the mathematical sense, see
54
+ # http://en.wikipedia.org/wiki/Pole_(complex_analysis) . "Single Pole"
55
+ # means a particular mathematical transformation of the filter function has
56
+ # a single pole, see
57
+ # http://ccrma.stanford.edu/~jos/filters/Pole_Zero_Analysis_I.html .
58
+ # Furthermore, a single-pole filter must have an inverse square decline
59
+ # (or -20 db/decade). Since the filter plotted here does have that
60
+ # characteristic, it must by definition be a single-pole filter, see also
61
+ # http://www-k.ext.ti.com/SRVS/Data/ti/KnowledgeBases/analog/document/faqs/1p.htm
62
+ # (5) decade represents a factor of 10, see
63
+ # http://en.wikipedia.org/wiki/Decade_(log_scale) .
64
+
65
+ X_LABEL = [
66
+ "Frequency",
67
+ "Частота",
68
+ ]
69
+
70
+ Y_LABEL = [
71
+ "Amplitude (dB)",
72
+ "Амплитуда (dB)",
73
+ ]
74
+
75
+ ALTY_LABEL = [
76
+ "Phase shift (degrees)",
77
+ "Фазовый сдвиг (градусы)",
78
+ ]
79
+
80
+ TITLE_LABEL = [
81
+ "Single Pole Low-Pass Filter",
82
+ "Однополюсный Низко-Частотный Фильтр",
83
+ ]
84
+
85
+ LINE_LABEL = [
86
+ "-20 dB/decade",
87
+ "-20 dB/десяток",
88
+ ]
89
+
90
+ # Makes transliteration from C example easier
91
+ def pow(a,b)
92
+ a ** b
93
+ end
94
+
95
+ #--------------------------------------------------------------------------
96
+ # plot1
97
+ #
98
+ # Log-linear plot.
99
+ #--------------------------------------------------------------------------
100
+
101
+ def plot1(type, x_label, y_label, alty_label, title_label, line_label)
102
+
103
+ pladv(0)
104
+
105
+ # Set up data for log plot
106
+
107
+ freql = NArray.float(101)
108
+ ampl = NArray.float(101)
109
+ phase = NArray.float(101)
110
+
111
+ f0 = 1.0
112
+ 101.times do |i|
113
+ freql[i] = -2.0 + i / 20.0
114
+ freq = pow(10.0, freql[i])
115
+ ampl[i] = 20.0 * log10(1.0 / sqrt(1.0 + pow(freq / f0, 2)))
116
+ phase[i] = -(180 / PI) * atan(freq / f0)
117
+ end
118
+
119
+ plvpor(0.15, 0.85, 0.1, 0.9)
120
+ plwind(-2.0, 3.0, -80.0, 0.0)
121
+
122
+ # Try different axis and labelling styles.
123
+
124
+ plcol0(1)
125
+ case (type)
126
+ when 0
127
+ plbox("bclnst", 0.0, 0, "bnstv", 0.0, 0)
128
+ when 1
129
+ plbox("bcfghlnst", 0.0, 0, "bcghnstv", 0.0, 0)
130
+ end
131
+
132
+ # Plot ampl vs freq
133
+
134
+ plcol0(2)
135
+ plline(freql, ampl)
136
+ plcol0(1)
137
+ plptex(1.6, -30.0, 1.0, -20.0, 0.5, line_label)
138
+
139
+ # Put labels on
140
+
141
+ plcol0(1)
142
+ plmtex("b", 3.2, 0.5, 0.5, x_label)
143
+ plmtex("t", 2.0, 0.5, 0.5, title_label)
144
+ plcol0(2)
145
+ plmtex("l", 5.0, 0.5, 0.5, y_label)
146
+
147
+ # For the gridless case, put phase vs freq on same plot
148
+
149
+ if (type == 0)
150
+ plcol0(1)
151
+ plwind(-2.0, 3.0, -100.0, 0.0)
152
+ plbox("", 0.0, 0, "cmstv", 30.0, 3)
153
+ plcol0(3)
154
+ plline(freql, phase)
155
+ plcol0(3)
156
+ plmtex("r", 5.0, 0.5, 0.5, alty_label)
157
+ end
158
+ end
159
+
160
+ #--------------------------------------------------------------------------
161
+ # Illustration of logarithmic axes, and redefinition of window.
162
+ #--------------------------------------------------------------------------
163
+
164
+ # Parse and process command line arguments
165
+
166
+ PLOptionParser.parse!
167
+
168
+ # Initialize plplot
169
+
170
+ plinit()
171
+ plfont(2)
172
+
173
+ # Make log plots using two different styles.
174
+
175
+ X_LABEL.each_index do |i|
176
+ plot1(i, X_LABEL[i], Y_LABEL[i], ALTY_LABEL[i], TITLE_LABEL[i],
177
+ LINE_LABEL[i])
178
+ end
179
+
180
+ plend
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env ruby
2
+ $-w = true if $0 == __FILE__
3
+
4
+ require 'rubygems'
5
+ require 'plplot'
6
+ include PLplot
7
+ include NMath
8
+
9
+ # Drawing "spirograph" curves - epitrochoids, cycolids, roulettes
10
+ #
11
+ # Copyright (C) 2007 Arjen Markus
12
+ #
13
+ # This file is part of PLplot.
14
+ #
15
+ # PLplot is free software; you can redistribute it and/or modify
16
+ # it under the terms of the GNU General Library Public License as published
17
+ # by the Free Software Foundation; either version 2 of the License, or
18
+ # (at your option) any later version.
19
+ #
20
+ # PLplot is distributed in the hope that it will be useful,
21
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ # GNU Library General Public License for more details.
24
+ #
25
+ # You should have received a copy of the GNU Library General Public License
26
+ # along with PLplot; if not, write to the Free Software
27
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28
+
29
+ def cycloid
30
+ # TODO
31
+ end
32
+
33
+ NPNT = 20000
34
+
35
+ def spiro(params)
36
+
37
+ # Fill the coordinates
38
+
39
+ windings = params[3].to_i
40
+ steps = NPNT / windings
41
+ dphi = 8.0 * acos(-1.0) / steps
42
+
43
+ p01 = params[0] - params[1]
44
+ npnt = windings * steps + 1
45
+ phi = NArray.float(npnt).indgen!.mul!(dphi)
46
+ phiw = NArray.float(npnt).indgen!.mul!(dphi * p01 / params[1])
47
+ xcoord = cos(phi).mul!(p01) + cos(phiw).mul!(params[2])
48
+ ycoord = sin(phi).mul!(p01) - sin(phiw).mul!(params[2])
49
+
50
+ xmin = xcoord.min
51
+ xmax = xcoord.max
52
+ ymin = ycoord.min
53
+ ymax = ycoord.max
54
+
55
+ if (xmax - xmin > ymax - ymin)
56
+ scale = xmax - xmin
57
+ else
58
+ scale = ymax - ymin
59
+ end
60
+ xmin = -0.65 * scale
61
+ xmax = 0.65 * scale
62
+ ymin = -0.65 * scale
63
+ ymax = 0.65 * scale
64
+
65
+ plwind(xmin, xmax, ymin, ymax)
66
+
67
+ plcol0(1)
68
+ plline(xcoord, ycoord)
69
+ end
70
+
71
+ #--------------------------------------------------------------------------
72
+ # Generates two kinds of plots:
73
+ # - construction of a cycloid (animated)
74
+ # - series of epitrochoids and hypotrochoids
75
+ #--------------------------------------------------------------------------
76
+
77
+ # R, r, p, N
78
+ params = [
79
+ [21.0, 7.0, 7.0, 3.0], # Deltoid
80
+ [21.0, 7.0, 10.0, 3.0],
81
+ [21.0, -7.0, 10.0, 3.0],
82
+ [20.0, 3.0, 7.0, 20.0],
83
+ [20.0, 3.0, 10.0, 20.0],
84
+ [20.0, -3.0, 10.0, 20.0],
85
+ [20.0, 13.0, 7.0, 20.0],
86
+ [20.0, 13.0, 20.0, 20.0],
87
+ [20.0, -13.0, 20.0, 20.0]
88
+ ]
89
+
90
+ # Parse and process command line arguments
91
+
92
+ PLOptionParser.parse!
93
+
94
+ # Initialize plplot
95
+
96
+ plinit
97
+
98
+ # Illustrate the construction of a cycloid
99
+
100
+ cycloid
101
+
102
+ # Loop over the various curves
103
+ # First an overview, then all curves one by one
104
+
105
+ plssub(3, 3) # Three by three window
106
+
107
+ 9.times do |i|
108
+ pladv(0)
109
+ plvpor(0.0, 1.0, 0.0, 1.0)
110
+ spiro(params[i])
111
+ end
112
+
113
+ pladv(0)
114
+ plssub(1, 1) # One window per curve
115
+
116
+ 9.times do |i|
117
+ pladv(0)
118
+ plvpor(0.0, 1.0, 0.0, 1.0)
119
+ spiro(params[i])
120
+ end
121
+
122
+ # Don't forget to call plend to finish off!
123
+
124
+ plend
@@ -0,0 +1,369 @@
1
+ #!/usr/bin/env ruby
2
+ $-w = true if $0 == __FILE__
3
+
4
+ require 'rubygems'
5
+ require 'plplot'
6
+ include PLplot
7
+ include Math
8
+
9
+ # plmtex3, plptex3 demo.
10
+ #
11
+ # Copyright (C) 2007, 2008, 2009 Alan W. Irwin
12
+ #
13
+ # This file is part of PLplot.
14
+ #
15
+ # PLplot is free software; you can redistribute it and/or modify
16
+ # it under the terms of the GNU General Library Public License as published
17
+ # by the Free Software Foundation; either version 2 of the License, or
18
+ # (at your option) any later version.
19
+ #
20
+ # PLplot is distributed in the hope that it will be useful,
21
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ # GNU Library General Public License for more details.
24
+ #
25
+ # You should have received a copy of the GNU Library General Public License
26
+ # along with PLplot; if not, write to the Free Software
27
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28
+
29
+ # Choose these values to correspond to tick marks. */
30
+ XPTS = 2
31
+ YPTS = 2
32
+ NREVOLUTION = 16
33
+ NROTATION = 8
34
+ NSHEAR = 8
35
+
36
+ #--------------------------------------------------------------------------
37
+ # Demonstrates plotting text in 3D.
38
+ #--------------------------------------------------------------------------
39
+
40
+
41
+ xmin = 0.0; xmax = 1.0; xmid = 0.5 * (xmax + xmin); xrange = xmax - xmin
42
+ ymin = 0.0; ymax = 1.0; ymid = 0.5 * (ymax + ymin); yrange = ymax - ymin
43
+ zmin = 0.0; zmax = 1.0; zmid = 0.5 * (zmax + zmin); zrange = zmax - zmin
44
+ ysmin = ymin + 0.1 * yrange
45
+ ysmax = ymax - 0.1 * yrange
46
+ ysrange = ysmax - ysmin
47
+ dysrot = ysrange / (NROTATION - 1)
48
+ dysshear = ysrange / (NSHEAR - 1)
49
+ zsmin = zmin + 0.1 * zrange
50
+ zsmax = zmax - 0.1 * zrange
51
+ zsrange = zsmax - zsmin
52
+ dzsrot = zsrange / (NROTATION - 1)
53
+ dzsshear = zsrange / (NSHEAR - 1)
54
+ pstring = "The future of our civilization depends on software freedom."
55
+
56
+ # Allocate and define the minimal x, y, and z to insure 3D box
57
+ x = NArray.float(XPTS).indgen!.mul!((xmax-xmin)/(XPTS-1)) + xmin
58
+ y = NArray.float(YPTS).indgen!.mul!((ymax-ymin)/(YPTS-1)) + ymin
59
+ z = NArray.float(YPTS, XPTS)
60
+
61
+ # Parse and process command line arguments
62
+
63
+ PLOptionParser.parse!
64
+
65
+ plinit
66
+
67
+ # Page 1: Demonstrate inclination and shear capability pattern. */
68
+
69
+ pladv(0)
70
+ plvpor(-0.15, 1.15, -0.05, 1.05)
71
+ plwind(-1.2, 1.2, -0.8, 1.5)
72
+ plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax,
73
+ 20.0, 45.0)
74
+
75
+ plcol0(2)
76
+ plbox3("b", "", xmax - xmin, 0,
77
+ "b", "", ymax - ymin, 0,
78
+ "bcd", "", zmax - zmin, 0)
79
+
80
+ # z = zmin
81
+ plschr(0, 1)
82
+ NREVOLUTION.times do |i|
83
+ omega = 2 * PI * i / NREVOLUTION
84
+ sin_omega = sin(omega)
85
+ cos_omega = cos(omega)
86
+ x_inclination = 0.5 * xrange * cos_omega
87
+ y_inclination = 0.5 * yrange * sin_omega
88
+ z_inclination = 0.0
89
+ x_shear = -0.5 * xrange * sin_omega
90
+ y_shear = 0.5 * yrange * cos_omega
91
+ z_shear = 0.0
92
+ plptex3(
93
+ xmid, ymid, zmin,
94
+ x_inclination, y_inclination, z_inclination,
95
+ x_shear, y_shear, z_shear,
96
+ 0.0, " revolution")
97
+ end
98
+
99
+ # x = xmax
100
+ plschr(0, 1)
101
+ NREVOLUTION.times do |i|
102
+ omega = 2 * PI * i / NREVOLUTION
103
+ sin_omega = sin(omega)
104
+ cos_omega = cos(omega)
105
+ x_inclination = 0.0
106
+ y_inclination = -0.5 * yrange * cos_omega
107
+ z_inclination = 0.5 * zrange * sin_omega
108
+ x_shear = 0.0
109
+ y_shear = 0.5 * yrange * sin_omega
110
+ z_shear = 0.5 * zrange * cos_omega
111
+ plptex3(
112
+ xmax, ymid, zmid,
113
+ x_inclination, y_inclination, z_inclination,
114
+ x_shear, y_shear, z_shear,
115
+ 0.0, " revolution")
116
+ end
117
+
118
+ # y = ymax
119
+ plschr(0, 1)
120
+ NREVOLUTION.times do |i|
121
+ omega = 2 * PI * i / NREVOLUTION
122
+ sin_omega = sin(omega)
123
+ cos_omega = cos(omega)
124
+ x_inclination = 0.5 * xrange * cos_omega
125
+ y_inclination = 0.0
126
+ z_inclination = 0.5 * zrange * sin_omega
127
+ x_shear = -0.5 * xrange * sin_omega
128
+ y_shear = 0.0
129
+ z_shear = 0.5 * zrange * cos_omega
130
+ plptex3(
131
+ xmid, ymax, zmid,
132
+ x_inclination, y_inclination, z_inclination,
133
+ x_shear, y_shear, z_shear,
134
+ 0.0, " revolution")
135
+ end
136
+ # Draw minimal 3D grid to finish defining the 3D box.
137
+ plmesh(x, y, z, PL::DRAW_LINEXY)
138
+
139
+ # Page 2: Demonstrate rotation of string around its axis.
140
+ pladv(0)
141
+ plvpor(-0.15, 1.15, -0.05, 1.05)
142
+ plwind(-1.2, 1.2, -0.8, 1.5)
143
+ plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax,
144
+ 20.0, 45.0)
145
+
146
+ plcol0(2)
147
+ plbox3("b", "", xmax - xmin, 0,
148
+ "b", "", ymax - ymin, 0,
149
+ "bcd", "", zmax - zmin, 0)
150
+
151
+ # y = ymax
152
+ plschr(0, 1)
153
+ x_inclination = 1
154
+ y_inclination = 0
155
+ z_inclination = 0
156
+ x_shear = 0
157
+ NROTATION.times do |i|
158
+ omega = 2 * PI * i / NROTATION
159
+ sin_omega = sin(omega)
160
+ cos_omega = cos(omega)
161
+ y_shear = 0.5 * yrange * sin_omega
162
+ z_shear = 0.5 * zrange * cos_omega
163
+ zs = zsmax - dzsrot * i
164
+ plptex3(
165
+ xmid, ymax, zs,
166
+ x_inclination, y_inclination, z_inclination,
167
+ x_shear, y_shear, z_shear,
168
+ 0.5, "rotation for y = y#dmax#u")
169
+ end
170
+
171
+ # x = xmax
172
+ plschr(0, 1)
173
+ x_inclination = 0
174
+ y_inclination = -1
175
+ z_inclination = 0
176
+ y_shear = 0
177
+ NROTATION.times do |i|
178
+ omega = 2 * PI * i / NROTATION
179
+ sin_omega = sin(omega)
180
+ cos_omega = cos(omega)
181
+ x_shear = 0.5 * xrange * sin_omega
182
+ z_shear = 0.5 * zrange * cos_omega
183
+ zs = zsmax - dzsrot * i
184
+ plptex3(
185
+ xmax, ymid, zs,
186
+ x_inclination, y_inclination, z_inclination,
187
+ x_shear, y_shear, z_shear,
188
+ 0.5, "rotation for x = x#dmax#u")
189
+ end
190
+
191
+ # z = zmin
192
+ plschr(0, 1)
193
+ x_inclination = 1
194
+ y_inclination = 0
195
+ z_inclination = 0
196
+ x_shear = 0
197
+ NROTATION.times do |i|
198
+ omega = 2 * PI * i / NROTATION
199
+ sin_omega = sin(omega)
200
+ cos_omega = cos(omega)
201
+ y_shear = 0.5 * yrange * cos_omega
202
+ z_shear = 0.5 * zrange * sin_omega
203
+ ys = ysmax - dysrot * i
204
+ plptex3(
205
+ xmid, ys, zmin,
206
+ x_inclination, y_inclination, z_inclination,
207
+ x_shear, y_shear, z_shear,
208
+ 0.5, "rotation for z = z#dmin#u")
209
+ end
210
+ # Draw minimal 3D grid to finish defining the 3D box. */
211
+ plmesh(x, y, z, PL::DRAW_LINEXY)
212
+
213
+ # Page 3: Demonstrate shear of string along its axis.
214
+ # Work around xcairo and pngcairo (but not pscairo) problems for
215
+ # shear vector too close to axis of string. (N.B. no workaround
216
+ # would be domega = 0.)
217
+ domega = 0.05
218
+ pladv(0)
219
+ plvpor(-0.15, 1.15, -0.05, 1.05)
220
+ plwind(-1.2, 1.2, -0.8, 1.5)
221
+ plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax,
222
+ 20.0, 45.0)
223
+
224
+ plcol0(2)
225
+ plbox3("b", "", xmax - xmin, 0,
226
+ "b", "", ymax - ymin, 0,
227
+ "bcd", "", zmax - zmin, 0)
228
+
229
+ # y = ymax
230
+ plschr(0, 1)
231
+ x_inclination = 1
232
+ y_inclination = 0
233
+ z_inclination = 0
234
+ y_shear = 0
235
+ NSHEAR.times do |i|
236
+ omega = domega + 2 * PI * i / NSHEAR
237
+ sin_omega = sin(omega)
238
+ cos_omega = cos(omega)
239
+ x_shear = 0.5 * xrange * sin_omega
240
+ z_shear = 0.5 * zrange * cos_omega
241
+ zs = zsmax - dzsshear * i
242
+ plptex3(
243
+ xmid, ymax, zs,
244
+ x_inclination, y_inclination, z_inclination,
245
+ x_shear, y_shear, z_shear,
246
+ 0.5, "shear for y = y#dmax#u")
247
+ end
248
+
249
+ # x = xmax
250
+ plschr(0, 1)
251
+ x_inclination = 0
252
+ y_inclination = -1
253
+ z_inclination = 0
254
+ x_shear = 0
255
+ NSHEAR.times do |i|
256
+ omega = domega + 2 * PI * i / NSHEAR
257
+ sin_omega = sin(omega)
258
+ cos_omega = cos(omega)
259
+ y_shear = -0.5 * yrange * sin_omega
260
+ z_shear = 0.5 * zrange * cos_omega
261
+ zs = zsmax - dzsshear * i
262
+ plptex3(
263
+ xmax, ymid, zs,
264
+ x_inclination, y_inclination, z_inclination,
265
+ x_shear, y_shear, z_shear,
266
+ 0.5, "shear for x = x#dmax#u")
267
+ end
268
+
269
+ # z = zmin
270
+ plschr(0, 1)
271
+ x_inclination = 1
272
+ y_inclination = 0
273
+ z_inclination = 0
274
+ z_shear = 0
275
+ NSHEAR.times do |i|
276
+ omega = domega + 2 * PI * i / NSHEAR
277
+ sin_omega = sin(omega)
278
+ cos_omega = cos(omega)
279
+ y_shear = 0.5 * yrange * cos_omega
280
+ x_shear = 0.5 * xrange * sin_omega
281
+ ys = ysmax - dysshear * i
282
+ plptex3(
283
+ xmid, ys, zmin,
284
+ x_inclination, y_inclination, z_inclination,
285
+ x_shear, y_shear, z_shear,
286
+ 0.5, "shear for z = z#dmin#u")
287
+ end
288
+ # Draw minimal 3D grid to finish defining the 3D box.
289
+ plmesh(x, y, z, PL::DRAW_LINEXY)
290
+
291
+ # Page 4: Demonstrate drawing a string on a 3D path.
292
+ pladv(0)
293
+ plvpor(-0.15, 1.15, -0.05, 1.05)
294
+ plwind(-1.2, 1.2, -0.8, 1.5)
295
+ plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax,
296
+ 40.0, -30.0)
297
+
298
+ plcol0(2)
299
+ plbox3("b", "", xmax - xmin, 0,
300
+ "b", "", ymax - ymin, 0,
301
+ "bcd", "", zmax - zmin, 0)
302
+
303
+ plschr(0, 1.2)
304
+ # domega controls the spacing between the various characters of the
305
+ # string and also the maximum value of omega for the given number
306
+ # of characters in *pstring.
307
+ domega = 2 * PI / pstring.length
308
+ omega = 0
309
+ # 3D function is a helix of the given radius and pitch
310
+ radius = 0.5
311
+ pitch = 1 / (2 * PI)
312
+ pstring.split('').each do |p1string|
313
+ sin_omega = sin(omega)
314
+ cos_omega = cos(omega)
315
+ xpos = xmid + radius * sin_omega
316
+ ypos = ymid - radius * cos_omega
317
+ zpos = zmin + pitch * omega
318
+ # In general, the inclination is proportional to the derivative of
319
+ # the position wrt theta.
320
+ x_inclination = radius * cos_omega
321
+ y_inclination = radius * sin_omega
322
+ z_inclination = pitch
323
+ # The shear vector should be perpendicular to the 3D line with Z
324
+ # component maximized, but for low pitch a good approximation is
325
+ # a constant vector that is parallel to the Z axis.
326
+ x_shear = 0
327
+ y_shear = 0
328
+ z_shear = 1
329
+ plptex3(
330
+ xpos, ypos, zpos,
331
+ x_inclination, y_inclination, z_inclination,
332
+ x_shear, y_shear, z_shear,
333
+ 0.5, p1string)
334
+
335
+ omega += domega
336
+ end
337
+ # Draw minimal 3D grid to finish defining the 3D box.
338
+ plmesh(x, y, z, PL::DRAW_LINEXY)
339
+
340
+ # Page 5: Demonstrate plmtex3 axis labelling capability
341
+ pladv(0)
342
+ plvpor(-0.15, 1.15, -0.05, 1.05)
343
+ plwind(-1.2, 1.2, -0.8, 1.5)
344
+ plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax,
345
+ 20.0, 45.0)
346
+
347
+ plcol0(2)
348
+ plbox3("b", "", xmax - xmin, 0,
349
+ "b", "", ymax - ymin, 0,
350
+ "bcd", "", zmax - zmin, 0)
351
+
352
+ plschr(0, 1)
353
+ plmtex3("xp", 3.0, 0.5, 0.5, "Arbitrarily displaced")
354
+ plmtex3("xp", 4.5, 0.5, 0.5, "primary X-axis label")
355
+ plmtex3("xs", -2.5, 0.5, 0.5, "Arbitrarily displaced")
356
+ plmtex3("xs", -1.0, 0.5, 0.5, "secondary X-axis label")
357
+ plmtex3("yp", 3.0, 0.5, 0.5, "Arbitrarily displaced")
358
+ plmtex3("yp", 4.5, 0.5, 0.5, "primary Y-axis label")
359
+ plmtex3("ys", -2.5, 0.5, 0.5, "Arbitrarily displaced")
360
+ plmtex3("ys", -1.0, 0.5, 0.5, "secondary Y-axis label")
361
+ plmtex3("zp", 4.5, 0.5, 0.5, "Arbitrarily displaced")
362
+ plmtex3("zp", 3.0, 0.5, 0.5, "primary Z-axis label")
363
+ plmtex3("zs", -2.5, 0.5, 0.5, "Arbitrarily displaced")
364
+ plmtex3("zs", -1.0, 0.5, 0.5, "secondary Z-axis label")
365
+ # Draw minimal 3D grid to finish defining the 3D box.
366
+ plmesh(x, y, z, PL::DRAW_LINEXY)
367
+
368
+ # Clean up
369
+ plend