Root/nanonote-files/example-files/data/Examples/lua-plplot-examples/x18.lua

1--[[ $Id: x18.lua 9526 2009-02-13 22:06:13Z smekal $
2
3    3-d line and point plot demo. Adapted from x08c.c.
4
5  Copyright (C) 2008 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-- initialise Lua bindings for PLplot examples.
25dofile("plplot_examples.lua")
26
27function test_poly(k)
28  draw= { { 1, 1, 1, 1 },
29          { 1, 0, 1, 0 },
30          { 0, 1, 0, 1 },
31          { 1, 1, 0, 0 } }
32
33  x = {}
34  y = {}
35  z = {}
36
37  pl.adv(0)
38  pl.vpor(0, 1, 0, 0.9)
39  pl.wind(-1, 1, -0.9, 1.1)
40  pl.col0(1)
41  pl.w3d(1, 1, 1, -1, 1, -1, 1, -1, 1, alt[k], az[k])
42  pl.box3("bnstu", "x axis", 0, 0,
43          "bnstu", "y axis", 0, 0,
44          "bcdmnstuv", "z axis", 0, 0)
45
46  pl.col0(2)
47
48  -- x = r sin(phi) cos(theta)
49  -- y = r sin(phi) sin(theta)
50  -- z = r cos(phi)
51  -- r = 1 :=)
52
53  for i=0, 19 do
54    for j=0, 19 do
55        x[1] = math.sin( math.pi*j/20.1 ) * math.cos( 2*math.pi*i/20 )
56        y[1] = math.sin( math.pi*j/20.1 ) * math.sin( 2*math.pi*i/20 )
57        z[1] = math.cos( math.pi*j/20.1 )
58        
59        x[2] = math.sin( math.pi*(j+1)/20.1 ) * math.cos( 2*math.pi*i/20 )
60        y[2] = math.sin( math.pi*(j+1)/20.1 ) * math.sin( 2*math.pi*i/20 )
61        z[2] = math.cos( math.pi*(j+1)/20.1 )
62        
63        x[3] = math.sin( math.pi*(j+1)/20.1 ) * math.cos( 2*math.pi*(i+1)/20 )
64        y[3] = math.sin( math.pi*(j+1)/20.1 ) * math.sin( 2*math.pi*(i+1)/20 )
65        z[3] = math.cos( math.pi*(j+1)/20.1 )
66        
67        x[4] = math.sin( math.pi*j/20.1 ) * math.cos( 2*math.pi*(i+1)/20 )
68        y[4] = math.sin( math.pi*j/20.1 ) * math.sin( 2*math.pi*(i+1)/20 )
69        z[4] = math.cos( math.pi*j/20.1 )
70        
71        x[5] = math.sin( math.pi*j/20.1 ) * math.cos( 2*math.pi*i/20 )
72        y[5] = math.sin( math.pi*j/20.1 ) * math.sin( 2*math.pi*i/20 )
73        z[5] = math.cos( math.pi*j/20.1 )
74
75        pl.poly3( x, y, z, draw[k], 1 )
76    end
77  end
78
79  pl.col0(3)
80  pl.mtex("t", 1, 0.5, 0.5, "unit radius sphere" )
81end
82
83
84----------------------------------------------------------------------------
85-- main
86--
87-- Does a series of 3-d plots for a given data set, with different
88-- viewing options in each plot.
89----------------------------------------------------------------------------
90
91NPTS = 1000
92opt = { 1, 0, 1, 0 }
93alt = { 20, 35, 50, 65 }
94az = { 30, 40, 50, 60 }
95
96
97-- Parse and process command line arguments
98pl.parseopts(arg, pl.PL_PARSE_FULL)
99
100-- Initialize plplot
101pl.init()
102
103for k=1, 4 do
104    test_poly(k)
105end
106
107x = {}
108y = {}
109z = {}
110
111-- From the mind of a sick and twisted physicist...
112for i=1, NPTS do
113  z[i] = -1 + 2*(i-1)/NPTS
114
115  -- Pick one ...
116  -- r = 1 - (i-1) / NPTS
117  r = z[i]
118
119  x[i] = r * math.cos( 12*math.pi*(i-1)/NPTS )
120  y[i] = r * math.sin( 12*math.pi*(i-1)/NPTS )
121end
122
123for k=1, 4 do
124    pl.adv(0)
125    pl.vpor(0, 1, 0, 0.9)
126    pl.wind(-1, 1, -0.9, 1.1)
127    pl.col0(1)
128    pl.w3d(1, 1, 1, -1, 1, -1, 1, -1, 1, alt[k], az[k])
129    pl.box3("bnstu", "x axis", 0, 0,
130            "bnstu", "y axis", 0, 0,
131            "bcdmnstuv", "z axis", 0, 0)
132
133    pl.col0(2)
134
135    if opt[k]~=0 then
136    pl.line3( x, y, z )
137    else
138    pl.poin3( x, y, z, 1 )
139  end
140
141    pl.col0(3)
142    pl.mtex("t", 1.0, 0.5, 0.5, "#frPLplot Example 18 - Alt=" .. alt[k] .. ", Az=" .. az[k])
143end
144
145pl.plend()
146

Archive Download this file



interactive