File: x18.tcl

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 (123 lines) | stat: -rw-r--r-- 3,376 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
#----------------------------------------------------------------------------
# $Id: x18.tcl,v 1.9 2002/06/21 23:24:40 airwin Exp $
#----------------------------------------------------------------------------

proc x18 {{w loopback}} {

    matrix opt i 4 = {1, 0, 1, 0}
    matrix alt f 4 = {20.0, 35.0, 50.0, 65.0}
    matrix az  f 4 = {30.0, 40.0, 50.0, 60.0}

    set npts 1000
    set pi 3.14159265358979323846

    for {set k 0} {$k < 4} {incr k} {
	test_poly $w $k
    }

    matrix x f $npts
    matrix y f $npts
    matrix z f $npts

# From the mind of a sick and twisted physicist...

    for {set i 0} {$i < $npts} {incr i} {
	z $i = [expr -1. + 2. * $i / $npts]

# Pick one ... 

#	r    = 1. - ( (float) i / (float) NPTS );
	set r [z $i]

	x $i = [expr $r * cos( 2. * $pi * 6. * $i / $npts )]
	y $i = [expr $r * sin( 2. * $pi * 6. * $i / $npts )]
    }

    for {set k 0} {$k < 4} {incr k} {
	$w cmd pladv 0
	$w cmd plvpor 0.0 1.0 0.0 0.9
	$w cmd plwind -1.0 1.0 -0.9 1.1
	$w cmd plcol0 1
	$w cmd plw3d 1.0 1.0 1.0 -1.0 1.0 -1.0 1.0 -1.0 1.0 [alt $k], [az $k]
	$w cmd plbox3 "bnstu" "x axis" 0.0 0 \
	    "bnstu" "y axis" 0.0 0 \
	    "bcdmnstuv" "z axis" 0.0 0

	$w cmd plcol0 2

	if {[opt $k]} {
	    $w cmd plline3 $npts x y z
	} else {
	    $w cmd plpoin3 $npts x y z 1
	}

	$w cmd plcol0 3
	set title [format "#frPLplot Example 18 - Alt=%.0f, Az=%.0f" \
		       [alt $k] [az $k]]
	$w cmd plmtex t 1.0 0.5 0.5 "$title"
    }
    # Restore defaults
    $w cmd plcol0 1
}

proc test_poly {{w loopback} k} {

    matrix draw0 i 4 = { 1, 1, 1, 1 }
    matrix draw1 i 4 = { 1, 0, 1, 0 }
    matrix draw2 i 4 = { 0, 1, 0, 1 }
    matrix draw3 i 4 = { 1, 1, 0, 0 }

    set pi 3.14159265358979323846; set two_pi [expr 2. * $pi]

    matrix x f 5
    matrix y f 5
    matrix z f 5

    $w cmd pladv 0
    $w cmd plvpor 0.0 1.0 0.0 0.9
    $w cmd plwind -1.0 1.0 -0.9 1.1
    $w cmd plcol0 1
    $w cmd plw3d 1.0 1.0 1.0 -1.0 1.0 -1.0 1.0 -1.0 1.0 [alt $k] [az $k]
    $w cmd plbox3 "bnstu" "x axis" 0.0 0 \
	"bnstu" "y axis" 0.0 0 \
	"bcdmnstuv" "z axis" 0.0 0

    $w cmd plcol0 2

#define THETA(a) (two_pi * (a) /20.)
#define PHI(a)    (pi * (a) / 20.1)

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

    for {set i 0} {$i < 20} {incr i} {
	for {set j 0} {$j < 20} {incr j} {
	    x 0 = [expr sin( $pi * $j / 20.1 ) * cos( $two_pi * $i / 20 )]
	    y 0 = [expr sin( $pi * $j / 20.1 ) * sin( $two_pi * $i / 20 )]
	    z 0 = [expr cos( $pi * $j / 20.1 )]

	    x 1 = [expr sin( $pi * ($j+1) / 20.1 ) * cos( $two_pi * $i / 20 )]
	    y 1 = [expr sin( $pi * ($j+1) / 20.1 ) * sin( $two_pi * $i / 20 )]
	    z 1 = [expr cos( $pi * ($j+1) / 20.1 )]

	    x 2 = [expr sin($pi * ($j+1) / 20.1) * cos($two_pi * ($i+1) / 20)]
	    y 2 = [expr sin($pi * ($j+1) / 20.1) * sin($two_pi * ($i+1) / 20)]
	    z 2 = [expr cos($pi * ($j+1) / 20.1)]

	    x 3 = [expr sin( $pi * $j / 20.1 ) * cos( $two_pi * ($i+1) / 20 )]
	    y 3 = [expr sin( $pi * $j / 20.1 ) * sin( $two_pi * ($i+1) / 20 )]
	    z 3 = [expr cos( $pi * $j / 20.1 )]

	    x 4 = [expr sin( $pi * $j / 20.1 ) * cos( $two_pi * $i / 20 )]
	    y 4 = [expr sin( $pi * $j / 20.1 ) * sin( $two_pi * $i / 20 )]
	    z 4 = [expr cos( $pi * $j / 20.1 )]

	    $w cmd plpoly3 5 x y z draw$k 1
	}
    }

    $w cmd plcol0 3
    $w cmd plmtex "t" 1.0 0.5 0.5 "unit radius sphere"
}