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