1# Copyright (C) 2007-2016 Alan W. Irwin 2 3# plmtex3, plptex3 demo. 4# 5# This file is part of PLplot. 6# 7# PLplot is free software; you can redistribute it and/or modify 8# it under the terms of the GNU Library General Public License as published 9# by the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# PLplot is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU Library General Public License for more details. 16# 17# You should have received a copy of the GNU Library General Public License 18# along with PLplot; if not, write to the Free Software 19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20# 21from numpy import * 22 23# Choose these values to correspond to tick marks. 24XPTS = 2 25YPTS = 2 26 27NREVOLUTION = 16 28NROTATION = 8 29NSHEAR = 8 30 31xmin = 0. 32xmax = 1.0 33xmid = 0.5*(xmax + xmin) 34xrange = xmax - xmin 35 36ymin = 0. 37ymax = 1.0 38ymid = 0.5*(ymax + ymin) 39yrange = ymax - ymin 40 41zmin = 0. 42zmax = 1.0 43zmid = 0.5*(zmax + zmin) 44zrange = zmax - zmin 45ysmin = ymin + 0.1 * yrange 46ysmax = ymax - 0.1 * yrange 47ysrange = ysmax - ysmin 48dysrot = ysrange / float( NROTATION - 1 ) 49dysshear = ysrange / float( NSHEAR - 1 ) 50zsmin = zmin + 0.1 * zrange 51zsmax = zmax - 0.1 * zrange 52zsrange = zsmax - zsmin 53dzsrot = zsrange / float( NROTATION - 1 ) 54dzsshear = zsrange / float( NSHEAR - 1 ) 55 56pstring = "The future of our civilization depends on software freedom." 57 58def main(w): 59 60 if 1: 61 x = xmin + (xmax-xmin)*arange(XPTS)/float(XPTS-1) 62 y = ymin + (ymax-ymin)*arange(YPTS)/float(YPTS-1) 63 z = reshape(0.+zeros(XPTS*YPTS),[XPTS,YPTS]) 64 65 if 1: 66 # Page 1: Demonstrate inclination and shear capability pattern. 67 68 w.pladv(0) 69 w.plvpor(-0.15, 1.15, -0.05, 1.05) 70 w.plwind(-1.2, 1.2, -0.8, 1.5) 71 w.plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45.) 72 73 w.plcol0(2) 74 w.plbox3( 75 "b", "", xmax-xmin, 0, 76 "b", "", ymax-ymin, 0, 77 "bcd", "", zmax-zmin, 0) 78 79 # z = zmin. 80 w.plschr(0., 1.0) 81 for i in range(NREVOLUTION): 82 omega = 2.*pi*(float(i)/float(NREVOLUTION)) 83 sin_omega = sin(omega) 84 cos_omega = cos(omega) 85 x_inclination = 0.5*xrange*cos_omega 86 y_inclination = 0.5*yrange*sin_omega 87 z_inclination = 0. 88 x_shear = -0.5*xrange*sin_omega 89 y_shear = 0.5*yrange*cos_omega 90 z_shear = 0. 91 w.plptex3( 92 xmid, ymid, zmin, 93 x_inclination, y_inclination, z_inclination, 94 x_shear, y_shear, z_shear, 95 0.0, " revolution") 96 97 # x = xmax. 98 w.plschr(0., 1.0) 99 for i in range(NREVOLUTION): 100 omega = 2.*pi*(float(i)/float(NREVOLUTION)) 101 sin_omega = sin(omega) 102 cos_omega = cos(omega) 103 x_inclination = 0. 104 y_inclination = -0.5*yrange*cos_omega 105 z_inclination = 0.5*zrange*sin_omega 106 x_shear = 0. 107 y_shear = 0.5*yrange*sin_omega 108 z_shear = 0.5*zrange*cos_omega 109 w.plptex3( 110 xmax, ymid, zmid, 111 x_inclination, y_inclination, z_inclination, 112 x_shear, y_shear, z_shear, 113 0.0, " revolution") 114 115 # y = ymax. 116 w.plschr(0., 1.0) 117 for i in range(NREVOLUTION): 118 omega = 2.*pi*(float(i)/float(NREVOLUTION)) 119 sin_omega = sin(omega) 120 cos_omega = cos(omega) 121 x_inclination = 0.5*xrange*cos_omega 122 y_inclination = 0. 123 z_inclination = 0.5*zrange*sin_omega 124 x_shear = -0.5*xrange*sin_omega 125 y_shear = 0. 126 z_shear = 0.5*zrange*cos_omega 127 w.plptex3( 128 xmid, ymax, zmid, 129 x_inclination, y_inclination, z_inclination, 130 x_shear, y_shear, z_shear, 131 0.0, " revolution") 132 # Draw minimal 3D grid to finish defining the 3D box. 133 w.plmesh(x, y, z, w.DRAW_LINEXY) 134 135 # Page 2: Demonstrate rotation of string around its axis. 136 137 w.pladv(0) 138 w.plvpor(-0.15, 1.15, -0.05, 1.05) 139 w.plwind(-1.2, 1.2, -0.8, 1.5) 140 w.plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45.) 141 142 w.plcol0(2) 143 w.plbox3( 144 "b", "", xmax-xmin, 0, 145 "b", "", ymax-ymin, 0, 146 "bcd", "", zmax-zmin, 0) 147 148 # y = ymax. 149 w.plschr(0., 1.0) 150 x_inclination = 1. 151 y_inclination = 0. 152 z_inclination = 0. 153 x_shear = 0. 154 for i in range(NROTATION): 155 omega = 2.*pi*(float(i)/float(NROTATION)) 156 sin_omega = sin(omega) 157 cos_omega = cos(omega) 158 y_shear = 0.5*yrange*sin_omega 159 z_shear = 0.5*zrange*cos_omega 160 zs = zsmax - dzsrot * float(i) 161 w.plptex3( 162 xmid, ymax, zs, 163 x_inclination, y_inclination, z_inclination, 164 x_shear, y_shear, z_shear, 165 0.5, "rotation for y = y#dmax#u") 166 167 # x = xmax. 168 w.plschr(0., 1.0) 169 x_inclination = 0. 170 y_inclination = -1. 171 z_inclination = 0. 172 y_shear = 0. 173 for i in range(NROTATION): 174 omega = 2.*pi*(float(i)/float(NROTATION)) 175 sin_omega = sin(omega) 176 cos_omega = cos(omega) 177 x_shear = 0.5*xrange*sin_omega 178 z_shear = 0.5*zrange*cos_omega 179 zs = zsmax - dzsrot * float(i) 180 w.plptex3( 181 xmax, ymid, zs, 182 x_inclination, y_inclination, z_inclination, 183 x_shear, y_shear, z_shear, 184 0.5, "rotation for x = x#dmax#u") 185 186 # z = zmin. 187 w.plschr(0., 1.0) 188 x_inclination = 1. 189 y_inclination = 0. 190 z_inclination = 0. 191 x_shear = 0. 192 for i in range(NROTATION): 193 omega = 2.*pi*(float(i)/float(NROTATION)) 194 sin_omega = sin(omega) 195 cos_omega = cos(omega) 196 y_shear = 0.5*yrange*cos_omega 197 z_shear = 0.5*zrange*sin_omega 198 ys = ysmax - dysrot * float(i) 199 w.plptex3( 200 xmid, ys, zmin, 201 x_inclination, y_inclination, z_inclination, 202 x_shear, y_shear, z_shear, 203 0.5, "rotation for z = z#dmin#u") 204 205 # Draw minimal 3D grid to finish defining the 3D box. 206 w.plmesh(x, y, z, w.DRAW_LINEXY) 207 208 # Page 3: Demonstrate shear of string along its axis. 209 210 # Work around xcairo and pngcairo (but not pscairo) problems for 211 # shear vector too close to axis of string. (N.B. no workaround 212 # would be domega = 0.) 213 domega = 0.05 214 w.pladv(0) 215 w.plvpor(-0.15, 1.15, -0.05, 1.05) 216 w.plwind(-1.2, 1.2, -0.8, 1.5) 217 w.plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45.) 218 219 w.plcol0(2) 220 w.plbox3( 221 "b", "", xmax-xmin, 0, 222 "b", "", ymax-ymin, 0, 223 "bcd", "", zmax-zmin, 0) 224 225 # y = ymax. 226 w.plschr(0., 1.0) 227 x_inclination = 1. 228 y_inclination = 0. 229 z_inclination = 0. 230 y_shear = 0. 231 for i in range(NSHEAR): 232 omega = domega + 2.*pi*(float(i)/float(NSHEAR)) 233 sin_omega = sin(omega) 234 cos_omega = cos(omega) 235 x_shear = 0.5*xrange*sin_omega 236 z_shear = 0.5*zrange*cos_omega 237 zs = zsmax - dzsshear * float(i) 238 w.plptex3( 239 xmid, ymax, zs, 240 x_inclination, y_inclination, z_inclination, 241 x_shear, y_shear, z_shear, 242 0.5, "shear for y = y#dmax#u") 243 244 # x = xmax. 245 w.plschr(0., 1.0) 246 x_inclination = 0. 247 y_inclination = -1. 248 z_inclination = 0. 249 x_shear = 0. 250 for i in range(NSHEAR): 251 omega = domega + 2.*pi*(float(i)/float(NSHEAR)) 252 sin_omega = sin(omega) 253 cos_omega = cos(omega) 254 y_shear = -0.5*yrange*sin_omega 255 z_shear = 0.5*zrange*cos_omega 256 zs = zsmax - dzsshear * float(i) 257 w.plptex3( 258 xmax, ymid, zs, 259 x_inclination, y_inclination, z_inclination, 260 x_shear, y_shear, z_shear, 261 0.5, "shear for x = x#dmax#u") 262 263 # z = zmin. 264 w.plschr(0., 1.0) 265 x_inclination = 1. 266 y_inclination = 0. 267 z_inclination = 0. 268 z_shear = 0. 269 for i in range(NSHEAR): 270 omega = domega + 2.*pi*(float(i)/float(NSHEAR)) 271 sin_omega = sin(omega) 272 cos_omega = cos(omega) 273 y_shear = 0.5*yrange*cos_omega 274 x_shear = 0.5*xrange*sin_omega 275 ys = ysmax - dysshear * float(i) 276 w.plptex3( 277 xmid, ys, zmin, 278 x_inclination, y_inclination, z_inclination, 279 x_shear, y_shear, z_shear, 280 0.5, "shear for z = z#dmin#u") 281 282 # Draw minimal 3D grid to finish defining the 3D box. 283 w.plmesh(x, y, z, w.DRAW_LINEXY) 284 285 # Page 4: Demonstrate drawing a string on a 3D path. 286 w.pladv(0) 287 w.plvpor(-0.15, 1.15, -0.05, 1.05) 288 w.plwind(-1.2, 1.2, -0.8, 1.5) 289 w.plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 40., -30.) 290 291 w.plcol0(2) 292 w.plbox3( 293 "b", "", xmax-xmin, 0, 294 "b", "", ymax-ymin, 0, 295 "bcd", "", zmax-zmin, 0) 296 297 w.plschr(0., 1.2) 298 # domega controls the spacing between the various characters of the 299 # string and also the maximum value of omega for the given number 300 # of characters in *pstring. 301 domega = 2.*pi/len(pstring) 302 omega = 0. 303 # 3D function is a helix of the given radius and pitch 304 radius = 0.5 305 pitch = 1./(2.*pi) 306 for character in pstring: 307 sin_omega = sin(omega) 308 cos_omega = cos(omega) 309 xpos = xmid + radius*sin_omega 310 ypos = ymid - radius*cos_omega 311 zpos = zmin + pitch*omega 312 # In general, the inclination is proportional to the derivative of 313 # the position wrt theta. 314 x_inclination = radius*cos_omega 315 y_inclination = radius*sin_omega 316 z_inclination = pitch 317 # The shear vector should be perpendicular to the 3D line with Z 318 # component maximized, but for low pitch a good approximation is 319 # a constant vector that is parallel to the Z axis. 320 x_shear = 0. 321 y_shear = 0. 322 z_shear = 1. 323 w.plptex3( 324 xpos, ypos, zpos, 325 x_inclination, y_inclination, z_inclination, 326 x_shear, y_shear, z_shear, 327 0.5, character) 328 omega += domega 329 330 # Draw minimal 3D grid to finish defining the 3D box. 331 w.plmesh(x, y, z, w.DRAW_LINEXY) 332 333 # Page 5: Demonstrate w.plmtex3 axis labelling capability. 334 w.pladv(0) 335 w.plvpor(-0.15, 1.15, -0.05, 1.05) 336 w.plwind(-1.2, 1.2, -0.8, 1.5) 337 w.plw3d(1.0, 1.0, 1.0, xmin, xmax, ymin, ymax, zmin, zmax, 20., 45.) 338 339 w.plcol0(2) 340 w.plbox3( 341 "b", "", xmax-xmin, 0, 342 "b", "", ymax-ymin, 0, 343 "bcd", "", zmax-zmin, 0) 344 345 w.plschr(0., 1.0) 346 w.plmtex3("xp", 3.0, 0.5, 0.5, "Arbitrarily displaced") 347 w.plmtex3("xp", 4.5, 0.5, 0.5, "primary X-axis label") 348 w.plmtex3("xs", -2.5, 0.5, 0.5, "Arbitrarily displaced") 349 w.plmtex3("xs", -1.0, 0.5, 0.5, "secondary X-axis label") 350 w.plmtex3("yp", 3.0, 0.5, 0.5, "Arbitrarily displaced") 351 w.plmtex3("yp", 4.5, 0.5, 0.5, "primary Y-axis label") 352 w.plmtex3("ys", -2.5, 0.5, 0.5, "Arbitrarily displaced") 353 w.plmtex3("ys", -1.0, 0.5, 0.5, "secondary Y-axis label") 354 w.plmtex3("zp", 4.5, 0.5, 0.5, "Arbitrarily displaced") 355 w.plmtex3("zp", 3.0, 0.5, 0.5, "primary Z-axis label") 356 w.plmtex3("zs", -2.5, 0.5, 0.5, "Arbitrarily displaced") 357 w.plmtex3("zs", -1.0, 0.5, 0.5, "secondary Z-axis label") 358 # Draw minimal 3D grid to finish defining the 3D box. 359 w.plmesh(x, y, z, w.DRAW_LINEXY) 360 361 # Restore defaults 362 w.plschr( 0.0, 1.0 ) 363 364 # Must be done independently because otherwise this changes output files 365 # and destroys agreement with C examples. 366 #w.plcol0(1) 367