File: xw18.py

package info (click to toggle)
plplot 5.3.1-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 26,248 kB
  • ctags: 11,687
  • sloc: ansic: 86,045; xml: 17,249; sh: 12,400; tcl: 8,113; cpp: 6,824; perl: 4,383; python: 3,915; makefile: 2,899; java: 2,788; fortran: 290; sed: 5; awk: 1
file content (133 lines) | stat: -rw-r--r-- 2,708 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from Numeric import *
from plplot import *

opt = [1, 0, 1, 0]

alt = [20.0, 35.0, 50.0, 65.0]

az = [30.0, 40.0, 50.0, 60.0]

# main
#
# Does a series of 3-d plots for a given data set, with different
# viewing options in each plot.

NPTS = 1000

def main():

	for k in range(4):
		test_poly(k)

	# From the mind of a sick and twisted physicist...
	
	z = -1. + (2./NPTS) * arrayrange(NPTS)
	x = z*cos((2.*pi*6./NPTS)*arrayrange(NPTS))
	y = z*sin((2.*pi*6./NPTS)*arrayrange(NPTS))

	for k in range(4):
		pladv(0)
		plvpor(0.0, 1.0, 0.0, 0.9)
		plwind(-1.0, 1.0, -0.9, 1.1)
		plcol0(1)
		plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0,
		       alt[k], az[k])
		plbox3("bnstu", "x axis", 0.0, 0,
			"bnstu", "y axis", 0.0, 0,
			"bcdmnstuv", "z axis", 0.0, 0)

		plcol0(2)

		if opt[k]:
			plline3(x, y, z)
		else:
			plpoin3(x, y, z, 1)

		plcol0(3)
		title = "#frPLplot Example 18 - Alt=%.0f, Az=%.0f" % (alt[k],
								      az[k])
		plmtex("t", 1.0, 0.5, 0.5, title)

	# Restore defaults
	plcol0(1)

def THETA(a):
    return 2. * pi * (a) / 20.

def PHI(a):
    return pi * (a) / 20.1

def test_poly(k):

	draw = [ [ 1, 1, 1, 1 ],
		 [ 1, 0, 1, 0 ],
		 [ 0, 1, 0, 1 ],
		 [ 1, 1, 0, 0 ] ]

	pladv(0)
	plvpor(0.0, 1.0, 0.0, 0.9)
	plwind(-1.0, 1.0, -0.9, 1.1)
	plcol0(1)
	plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k])
	plbox3("bnstu", "x axis", 0.0, 0,
		"bnstu", "y axis", 0.0, 0,
		"bcdmnstuv", "z axis", 0.0, 0)

	plcol0(2)

##      x = r sin(phi) cos(theta)
##      y = r sin(phi) sin(theta)
##      z = r cos(phi)
##      r = 1 :=)

	cosi0 = cos(THETA(arrayrange(20)))
	cosi1 = cos(THETA(arrayrange(1,21)))
	sini0 = sin(THETA(arrayrange(20)))
	sini1 = sin(THETA(arrayrange(1,21)))
	cosi0.shape = (-1,1)
	cosi1.shape = (-1,1)
	sini0.shape = (-1,1)
	sini1.shape = (-1,1)
	cosj0 = cos(PHI(arrayrange(20)))
	cosj1 = cos(PHI(arrayrange(1,21)))
	sinj0 = sin(PHI(arrayrange(20)))
	sinj1 = sin(PHI(arrayrange(1,21)))

	x0 = cosi0*sinj0
	y0 = sini0*sinj0
	z0 = cosj0
	
	x1 = cosi0*sinj1
	y1 = sini0*sinj1
	z1 = cosj1
	
	x2 = cosi1*sinj1
	y2 = sini1*sinj1
	z2 = cosj1
	
	x3 = cosi1*sinj0
	y3 = sini1*sinj0
	z3 = cosj0
	
	x4 = x0
	y4 = y0
	z4 = z0
	
	for i in range(20):
		for j in range(20):
		    
			x = [x0[i,j],x1[i,j],x2[i,j],x3[i,j],x4[i,j]]
			y = [y0[i,j],y1[i,j],y2[i,j],y3[i,j],y4[i,j]]
			z = [z0[j],z1[j],z2[j],z3[j],z4[j]]

			# Since negative dimensions don't make sense here 
			# to specify that points are to be drawn in 
			# counter-clockwise direction (as in x18c.c and
			# x18.tcl) this must be specified with an optional
			# extra argument in python API.
			plpoly3(x, y, z, draw[k], 1)

	plcol0(3)
	plmtex("t", 1.0, 0.5, 0.5, "unit radius sphere" )

main()