File: x18.tcl

package info (click to toggle)
plplot 5.15.0%2Bdfsg-19
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 31,312 kB
  • sloc: ansic: 79,707; xml: 28,583; cpp: 20,033; ada: 19,456; tcl: 12,081; f90: 11,431; ml: 7,276; java: 6,863; python: 6,792; sh: 3,274; perl: 828; lisp: 75; makefile: 50; sed: 34; fortran: 5
file content (119 lines) | stat: -rw-r--r-- 3,210 bytes parent folder | download | duplicates (4)
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
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

    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. * $::PLPLOT::PL_PI * 6. * $i / $npts )}]
	y $i = [expr {$r * sin( 2. * $::PLPLOT::PL_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 x y z
	} else {
	    # U+22C5 DOT OPERATOR.
	    $w cmd plstring3 x y z "⋅"
	}

	$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 $::PLPLOT::PL_PI; 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 x y z draw$k 1
	}
    }

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