1# -*- coding: utf-8; -*-
2
3#  Copyright (C) 2001-2016 Alan W. Irwin
4
5#  3-d line and point plot demo.
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 Library General 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
24from numpy import *
25
26opt = [1, 0, 1, 0]
27
28alt = [20.0, 35.0, 50.0, 65.0]
29
30az = [30.0, 40.0, 50.0, 60.0]
31
32# main
33#
34# Does a series of 3-d plots for a given data set, with different
35# viewing options in each plot.
36
37NPTS = 1000
38
39def main(w):
40
41        for k in range(4):
42                test_poly(w, k)
43
44        # From the mind of a sick and twisted physicist...
45
46        z = -1. + (2./NPTS) * arange(NPTS)
47        x = z*cos((2.*pi*6./NPTS)*arange(NPTS))
48        y = z*sin((2.*pi*6./NPTS)*arange(NPTS))
49
50        for k in range(4):
51                w.pladv(0)
52                w.plvpor(0.0, 1.0, 0.0, 0.9)
53                w.plwind(-1.0, 1.0, -0.9, 1.1)
54                w.plcol0(1)
55                w.plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0,
56                        alt[k], az[k])
57                w.plbox3("bnstu", "x axis", 0.0, 0,
58                         "bnstu", "y axis", 0.0, 0,
59                         "bcdmnstuv", "z axis", 0.0, 0)
60
61                w.plcol0(2)
62
63                if opt[k]:
64                        w.plline3(x, y, z)
65                else:
66                        # U+22C5 DOT OPERATOR.
67                        w.plstring3(x, y, z, "⋅")
68
69                w.plcol0(3)
70                title = "#frPLplot Example 18 - Alt=%.0f, Az=%.0f" % (alt[k], az[k])
71                w.plmtex("t", 1.0, 0.5, 0.5, title)
72
73        # Restore defaults
74        # Must be done independently because otherwise this changes output files
75        # and destroys agreement with C examples.
76        #w.plcol0(1)
77
78def THETA(a):
79    return 2. * pi * (a) / 20.
80
81def PHI(a):
82    return pi * (a) / 20.1
83
84def test_poly(w, k):
85
86        draw = [ [ 1, 1, 1, 1 ],
87                 [ 1, 0, 1, 0 ],
88                 [ 0, 1, 0, 1 ],
89                 [ 1, 1, 0, 0 ] ]
90
91        w.pladv(0)
92        w.plvpor(0.0, 1.0, 0.0, 0.9)
93        w.plwind(-1.0, 1.0, -0.9, 1.1)
94        w.plcol0(1)
95        w.plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k])
96        w.plbox3("bnstu", "x axis", 0.0, 0,
97                 "bnstu", "y axis", 0.0, 0,
98                 "bcdmnstuv", "z axis", 0.0, 0)
99
100        w.plcol0(2)
101
102#      x = r sin(phi) cos(theta)
103#      y = r sin(phi) sin(theta)
104#      z = r cos(phi)
105#      r = 1 :=)
106
107        cosi0 = cos(THETA(arange(20)))
108        cosi1 = cos(THETA(arange(1,21)))
109        sini0 = sin(THETA(arange(20)))
110        sini1 = sin(THETA(arange(1,21)))
111        cosi0.shape = (-1,1)
112        cosi1.shape = (-1,1)
113        sini0.shape = (-1,1)
114        sini1.shape = (-1,1)
115        cosj0 = cos(PHI(arange(20)))
116        cosj1 = cos(PHI(arange(1,21)))
117        sinj0 = sin(PHI(arange(20)))
118        sinj1 = sin(PHI(arange(1,21)))
119
120        x0 = cosi0*sinj0
121        y0 = sini0*sinj0
122        z0 = cosj0
123
124        x1 = cosi0*sinj1
125        y1 = sini0*sinj1
126        z1 = cosj1
127
128        x2 = cosi1*sinj1
129        y2 = sini1*sinj1
130        z2 = cosj1
131
132        x3 = cosi1*sinj0
133        y3 = sini1*sinj0
134        z3 = cosj0
135
136        x4 = x0
137        y4 = y0
138        z4 = z0
139
140        for i in range(20):
141                for j in range(20):
142
143                        x = [x0[i,j],x1[i,j],x2[i,j],x3[i,j],x4[i,j]]
144                        y = [y0[i,j],y1[i,j],y2[i,j],y3[i,j],y4[i,j]]
145                        z = [z0[j],z1[j],z2[j],z3[j],z4[j]]
146
147                        # Since negative dimensions don't make sense here
148                        # to specify that points are to be drawn in
149                        # counter-clockwise direction (as in x18c.c and
150                        # x18.tcl) this must be specified with an optional
151                        # extra argument in python API.
152                        w.plpoly3(x, y, z, draw[k], 1)
153
154        w.plcol0(3)
155        w.plmtex("t", 1.0, 0.5, 0.5, "unit radius sphere" )
156