forked from racket/racket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3d-tests.rkt
More file actions
256 lines (213 loc) · 9.21 KB
/
plot3d-tests.rkt
File metadata and controls
256 lines (213 loc) · 9.21 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#lang racket
(require plot plot/utils unstable/flonum)
;(plot-new-window? #t)
(time
(plot3d empty #:x-min -1 #:x-max 1 #:y-min -1 #:y-max 1 #:z-min -1 #:z-max 1))
(time
(plot3d (points3d empty) #:x-min -1 #:x-max 1 #:y-min -1 #:y-max 1 #:z-min -1 #:z-max 1))
(parameterize ([plot-background "black"]
[plot-foreground "white"]
[plot-background-alpha 1/2]
[plot-foreground-alpha 1/2])
(plot3d (surface3d (λ (x y) (* (sin x) (sin y))) -2 2 -2 2 #:label "z = trig(x,y)")))
(time
(plot3d (points3d '(#(0.1 0.6 0.3)))
#:x-min 0 #:x-max 1 #:y-min 0 #:y-max 1 #:z-min 0 #:z-max 1))
(time
(plot3d (vector-field3d (λ (x y z) (vector x z y)) -2 2 -2 2 -2 2
#:line-width 3)))
(time
(define x-ivls (bounds->intervals (linear-seq 2 8 10)))
(define y-ivls (bounds->intervals (linear-seq -5 5 10)))
(define x-mids (linear-seq 2 8 9 #:start? #f #:end? #f))
(define y-mids (linear-seq -5 5 9 #:start? #f #:end? #f))
(plot3d (rectangles3d (append*
(for/list ([y-ivl (in-list y-ivls)] [y (in-list y-mids)])
(for/list ([x-ivl (in-list x-ivls)] [x (in-list x-mids)])
(vector x-ivl y-ivl (ivl 0 (exp (* -1/2 (+ (sqr (- x 5)) (sqr y)))))))))
#:alpha 3/4
#:label "Approximate 2D Normal")))
(time
(plot3d (discrete-histogram3d (list (vector 'a 'a 1)
(vector 'a 'b 2)
(vector 'b 'b 3))
#:label "Missing (b,a)"
#:color 4 #:line-color 4)))
(time
(define c1s #(a b c d e))
(define c2s #(1 2 3 4 5))
(define cat-vals (build-list 15 (λ (n) (vector (vector-ref c1s (random 5))
(vector-ref c2s (random 5))
n))))
(plot3d (discrete-histogram3d cat-vals)))
(time
(plot3d (stacked-histogram3d '(#(a a (1 1 1)) #(a b (1.5 3)) #(b b ()) #(b a (1/2)))
#:labels '("Red" #f "Blue") #:alphas '(2/3))))
(time
(plot3d (stacked-histogram3d '(#(a a (1 1 1)) #(a b (1.5 3)) #(b b ()) #(b a (1/2)))
#:labels '("Red" #f "Blue") #:alphas '(2/3)
#:add-x-ticks? #f #:add-y-ticks? #f)))
(time
(plot3d (surface3d + 0 10 0 1)
#:angle 10 #:z-label "z axis"))
(parameterize ([plot-x-transform log-transform]
[plot-y-transform log-transform])
(time (plot3d (surface3d + .01 3 .01 1))))
;(plot-x-transform cbrt-transform)
;(plot-y-transform cbrt-transform)
;(plot-z-transform cbrt-transform)
(time
(plot3d (surface3d (λ (x y) (+ (/ 1.0 (exact->inexact x))
(/ 1.0 (exact->inexact y))))
-2 2 -2 2
#:color '(255 128 128)
#:line-color '(255 128 128)
#:line-width 1.5
#:label "Inverse")
#:title "Here it is!"
#:x-label "WannaHockaLoogi"
#:y-label "An Impossibly Long Y Axis Label"
#:angle 330 #:altitude 0))
(time
(plot3d (surface3d (λ (x y)
(+ (/ (+ (abs x) 0.01))
(/ (+ (abs y) 0.01))))
-4 4 -4 4 #:color '(128 128 255)
#:label "Z sort test polygons")
#:angle 330 #:altitude 41
#:z-label #f #:y-label #f #:x-label #f))
(let ()
(define xs (build-list 200 (λ (n) (/ 1 (- (random) 0.5)))))
(define ys (build-list 200 (λ (n) (/ 1 (- (random) 0.5)))))
(define zs (build-list 200 (λ (n) (/ 1 (- (random) 0.5)))))
(time
(plot3d (points3d (map vector xs ys zs)
#:x-min -20 #:x-max 20
#:y-min -20 #:y-max 20
#:z-min -20 #:z-max 20
#:label "Widget Locations")
#:angle 15 #:title "Random Points")))
(let ()
(define xs (build-list 10000 (λ (n) (/ 1 (- (random) 0.5)))))
(define ys (build-list 10000 (λ (n) (/ 1 (- (random) 0.5)))))
(define zs (build-list 10000 (λ (n) (/ 1 (- (random) 0.5)))))
(time
(plot3d (points3d (map vector xs ys zs)
#:x-min -20 #:x-max 20
#:y-min -20 #:y-max 20
#:z-min -20 #:z-max 20
#:color "blue" #:sym 'dot ;#:size 10
#:alpha 0.5)
#:angle 30 #:altitude 30
#:title "A Bunch of Random Points Concentrated at the Origin"
#:x-label "x" #:y-label "y" #:z-label "z")))
;; tests line clipping: should look like a sphere with six poles chopped off
(time
(plot3d (parametric3d (λ (t)
(vector (* (cos (* 80 t)) (cos t))
(* (sin (* 80 t)) (cos t))
(sin t)))
(- pi) pi
#:x-min -0.8 #:x-max 0.8
#:y-min -0.8 #:y-max 0.8
#:z-min -0.8 #:z-max 0.8
#:color "blue" #:width 1/2 #:style 'long-dash
#:samples 3000 #:alpha 0.5
#:label "Sphere")
#:altitude 22
#:x-min -1 #:x-max 1 #:y-min -1 #:y-max 1 #:z-min -1 #:z-max 1))
(time
(plot3d (surface3d (λ (x y) (+ x y)) -0.81 0.81 -0.81 0.81
#:line-color '(0 0 255) #:line-width 1 #:line-style 'dot)
#:x-min -1 #:x-max 1 #:y-min -1 #:y-max 1 #:z-min -1 #:z-max 1))
(time
(define xs (build-list 200 (λ (n) (* 2 (- (random) 0.5)))))
(define ys (build-list 200 (λ (n) (* 2 (- (random) 0.5)))))
(define zs (build-list 200 (λ (n) (* 2 (- (random) 0.5)))))
(plot3d (list (surface3d (λ (x y) (+ x y)) -0.81 0.81 -0.81 0.81
#:line-color '(0 0 255) #:line-width 1
#:line-style 'dot)
(points3d (map vector xs ys zs)))
#:x-min -1 #:x-max 1 #:y-min -1 #:y-max 1 #:z-min -1 #:z-max 1))
(define (norm mx my x y)
(exp (* -1/2 (+ (sqr (- x mx)) (sqr (- y my))))))
(define (f1 x y)
(- (sqr x) (sqr y)))
(define (f2 x y)
(- (sqrt (+ (abs y) (abs x)))))
(define (f3 x y)
(define d (* 2 pi (+ (abs x) (abs y))))
(+ (* 1/8 (cos d)) (- (sqr x) (sqr y))))
(define (f4 x y)
(imag-part (log (make-rectangular (exact->inexact x)
(exact->inexact y)))))
(define (f5 x y)
(+ (* 1.1 (norm -1.5 -1.5 x y))
(* 2 (norm 1 1 x y))
(* 1.3 (norm 2 -2 x y))))
(define (f6 x y)
(define d (sqrt (+ (sqr x) (sqr y))))
(if (d . < . 1)
(sqrt (- 1 (sqr d)))
0))
(parameterize ([plot3d-diffuse-light? #f]
[plot3d-specular-light? #f])
(time (plot3d (surface3d f5 -5 5 -5 5 #:style 'transparent))))
(time (plot3d (contours3d f5 -4 4 -4 4 #:colors '(0)
#:label "z")))
(time (plot3d (contour-intervals3d f5 -4 4 -4 4 #:label "z")))
(time (plot3d (contour-intervals3d
(λ (x y)
(define z (- x y))
(cond [(< z -1) -1]
[(> z 1) 1]
[else z]))
-2 2 -2 2)))
(time
(plot3d (contour-intervals3d (λ (x y) (+ x y)))
#:x-min #e100000000000000.0 #:x-max #e100000000000000.1
#:y-min #e100000000000000.0 #:y-max #e100000000000000.1
#:width 500))
(time
(plot3d (list (surface3d f5 0 4 -4 4 #:color '(128 255 160) #:alpha 0.5
#:label "x pos.")
(contour-intervals3d f5 -4 0 -4 4
#:colors '(0 1 5)
#:line-colors '(0 4 2)
#:line-widths '(1.5) #:line-styles '(dot)
#:contour-colors '(0)
#:contour-widths '(0)
#:contour-styles '(transparent)
#:alphas '(0.75)
#:label "x neg."))
#:z-min 0.25 #:z-max 1.1
#:legend-anchor 'top))
(time
(parameterize ([plot3d-samples 81])
(plot3d (contour-intervals3d
f5 -4 4 -4 4 #:label "z"
#:line-styles '(transparent)))))
(time
(plot3d (list (contours3d f5 -4 4 -4 4)
(contour-intervals3d f5 -2.5 2.5 -2.5 2.5
#:z-min 0.25 #:z-max 1.5 #:label "z"))))
(time
(plot3d (contour-intervals3d f5 -3 3 -3 3
#:colors '((255 128 128) (128 128 255)))))
(time
(plot3d (list (surface3d f4 -4 4 -4 4 #:color '(255 224 0))
(contours3d f4 -4 4 -4 4))
#:angle -30))
(time (plot3d (contour-intervals3d f1 -4 4 -4 4)))
(time (parameterize ([plot3d-samples 101])
(plot3d (contour-intervals3d f2 -2 2 -2 2 #:levels 10
#:line-styles '(transparent)
#:contour-styles '(long-dash)
#:alphas '(1 2/3))
#:altitude 20)))
(time
(plot3d (contour-intervals3d (λ (x y) (- (sqr x) (sqr y))) -min.0 +min.0 -min.0 +min.0)))
(time
(define (f x y) (* (sin x) (cos y)))
(plot3d (list (contour-intervals3d f -3 3 -3 3)
(point-label3d (list -1 1 (f -1 1))))))