-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPCM20220329_SICP_2.2.4_Example_A_Picture_Language.jl
2012 lines (1694 loc) · 74.6 KB
/
PCM20220329_SICP_2.2.4_Example_A_Picture_Language.jl
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### A Pluto.jl notebook ###
# v0.19.11
using Markdown
using InteractiveUtils
# ╔═╡ 7f5de9c5-b2da-4182-a663-26e5b5d286d6
using Plots
# ╔═╡ 0e89b190-af42-11ec-0b2f-9d505e202de3
md"""
=====================================================================================
#### SICP: 2.2.4 [Example: A Picture Language](https://sarabander.github.io/sicp/html/2_002e2.xhtml#g_t2_002e2_002e4)
###### file: PCM20220329\_SICP\_2.2.4\_Example\_A\_Picture\_Language.jl
###### Julia/Pluto.jl-code (1.8.0/19.11) by PCM *** 2022/09/07 ***
=====================================================================================
"""
# ╔═╡ 0e31932e-4091-4864-ae99-03b19aa2672d
md"""
SICP presents "*a simple language for drawing pictures that illustrates the power of data abstraction and closure, and also exploits higher-order procedures in an essential way. The language is designed to make it easy to experiment with patterns ... the operations in this language, which also satisfy the closure property, allow us to easily build arbitrarily complicated patterns.* (SICP, 1996, ch. 2.2.4, p.126)"
Under **closure** SICP means the *mathematical* [concept of closure](https://en.wikipedia.org/wiki/Closure_(mathematics)) but not the *computer science* [concept of closure](https://en.wikipedia.org/wiki/Closure_(computer_programming)). The problem here is to obtain a set of simple functions within Julia that meet the special requirements of SICP, especially the *closure* property.
"""
# ╔═╡ 64f13c08-ac4c-40c2-a74f-8f715e87c254
md"
###### [Plotly](https://plotly.com/julia/getting-started/) backend of *Plots* is recommended by the Pluto devs
"
# ╔═╡ 028a5028-eb2d-4144-8858-fa07636a9cc2
md"
---
#### 2.2.4.1 Painter Implementation without Frames
"
# ╔═╡ 4b322095-81e2-437c-aab7-30091a308729
md"
##### 'WaveMan' (ako 'Wave')
"
# ╔═╡ ba3519f0-e8f0-40d3-9cb9-e365310359ee
md"
###### 1st *method* of function 'makeWaveMan' (specialized with *two* arguments)
"
# ╔═╡ 04761c70-e9ea-4ba8-a24b-18db11578ca9
function makeWaveMan(x0, y0; normalize=false)
#--------------------------------------------------------------------------------
function polarToCartesianCoordinates(r, d)
(x, y) = (r * cosd(d), r * sind(d))
end
#--------------------------------------------------------------------------------
function shapeOfEye(;r=0.4)
shapeOfUnitCircle = [polarToCartesianCoordinates(r, degree) for degree in 0:15:360]
xsOfCircle = [shapeOfUnitCircle[i][1] for i in 1:25]
ysOfCircle = [shapeOfUnitCircle[i][2] for i in 1:25]
(xsOfCircle, ysOfCircle)
end
#--------------------------------------------------------------------------------
function normalizeZ(minX, lengthX, xs)
[(x - minX) / lengthX for x in xs]
end
#--------------------------------------------------------------------------------
xsBody = x0 .+ [4, 7, 8.5, 10.5, 13.5, 10.5, 18, 18, 13.5, 10.5, 11.5, 10.5, 7, 5.5, 6.5, 4.5, 2, -1, -1, 2, 4.5, 5.5, 4] # x-coordinates of body
ysBody = y0 .+ [.5, .5, 6, .5, .5, 9, 3.5, 7.5, 13, 13, 17, 20, 20, 17, 13, 13, 12, 17, 13, 8, 12, 10, .5] # y-coordinates of body
xsMouth = x0 .+ [ 7.5, 8.0, 9.0, 9.5, 7.5] # x-coordinates of mouth
ysMouth = (y0 - 0.5) .+ [16.0, 15.5, 15.5, 16.0, 16.0] # y-coordinates of mouth
xsNose = x0 .+ [ 8.0, 9.0, 8.5] # x-coordinates of nose
ysNose = (y0 - 0.8) .+ [17.0, 17.0, 18.0] # y-coordinates of nose
xsLeftEye = (x0 + 7.0) .+ shapeOfEye()[1] # x-coordinates of left eye
ysLeftEye = (y0 + 17.2) .+ shapeOfEye()[2] # y-coordinates of left eye
xsRightEye = (x0 + 10.0) .+ shapeOfEye()[1] # x-coordinates of right eye
ysRightEye = (y0 + 17.2) .+ shapeOfEye()[2] # y-coordinates of right eye
#--------------------------------------------------------------------------------
if normalize !== false
# normalize data points so that all points of figure lay inside a unit square
minX = minimum(xsBody); maxX = maximum(xsBody)
minY = minimum(ysBody); maxY = maximum(ysBody)
lengthX = maxX - minX
lengthY = maxY - minY
normalizedXsBody = normalizeZ(minX, lengthX, xsBody)
normalizedYsBody = normalizeZ(minY, lengthY, ysBody)
normalizedXsMouth = normalizeZ(minX, lengthX, xsMouth)
normalizedYsMouth = normalizeZ(minY, lengthY, ysMouth)
normalizedXsNose = normalizeZ(minX, lengthX, xsNose)
normalizedYsNose = normalizeZ(minY, lengthY, ysNose)
normalizedXsLeftEye = normalizeZ(minX, lengthX, xsLeftEye)
normalizedYsLeftEye = normalizeZ(minY, lengthY, ysLeftEye)
normalizedXsRightEye = normalizeZ(minX, lengthX, xsRightEye)
normalizedYsRightEye = normalizeZ(minY, lengthY, ysRightEye)
else
normalizedXsBody = xsBody
normalizedYsBody = ysBody
normalizedXsMouth = xsMouth
normalizedYsMouth = ysMouth
normalizedXsNose = xsNose
normalizedYsNose = ysNose
normalizedXsLeftEye = xsLeftEye
normalizedYsLeftEye = ysLeftEye
normalizedXsRightEye = xsRightEye
normalizedYsRightEye = ysRightEye
end # if
#--------------------------------------------------------------------------------
# application of constructor 'Shape'
(body=Shape(normalizedXsBody, normalizedYsBody), mouth=Shape(normalizedXsMouth, normalizedYsMouth), nose=Shape(normalizedXsNose, normalizedYsNose), leftEye=Shape(normalizedXsLeftEye, normalizedYsLeftEye), rightEye=Shape(normalizedXsRightEye, normalizedYsRightEye),layout=1)
end
# ╔═╡ ac03c7c1-9130-41f7-b5c0-5e10feac5171
md"
###### *unnormalized* 'waveMan'
"
# ╔═╡ bfa1b271-ae58-42c3-97f7-7fac72aae1f1
md"
###### *normalized* 'waveMan' (fits into [0, 1] x [0, 1] *unit* square)
"
# ╔═╡ 86a0b38a-fe3b-4520-9800-099f714b90e9
md"
###### 2nd (default) *method* of function 'makeWaveMan' (*without* arguments)
"
# ╔═╡ 5a1268af-abe6-4ac2-b350-0a8253864ba8
function makeWaveMan(;normalize=false)
#-----------------------------------------------------------------------------
function makeBody(x0, y0; normalize=normalize)::Shape{Float64, Float64}
makeWaveMan(x0, y0, normalize=normalize).body
end
function makeMouth(x0, y0; normalize=normalize)::Shape{Float64, Float64}
makeWaveMan(x0, y0, normalize=normalize).mouth
end
function makeNose(x0, y0; normalize=normalize)::Shape{Float64, Float64}
makeWaveMan(x0, y0, normalize=normalize).nose
end
function makeLeftEye(x0, y0; normalize=normalize)::Shape{Float64, Float64}
makeWaveMan(x0, y0, normalize=normalize).leftEye
end
function makeRightEye(x0, y0; normalize=normalize)::Shape{Float64, Float64}
makeWaveMan(x0, y0, normalize=normalize).rightEye
end
#-----------------------------------------------------------------------------
body = makeBody(0, 0, normalize=normalize)
mouth = makeMouth(0, 0, normalize=normalize)
nose = makeNose(0, 0, normalize=normalize)
leftEye = makeLeftEye(0, 0, normalize=normalize)
rightEye = makeRightEye(0, 0, normalize=normalize)
waveMan = hcat(body, mouth, nose, leftEye, rightEye)
#-----------------------------------------------------------------------------
(body=waveMan, layout=1)
end
# ╔═╡ fe4cd255-99db-43f6-8586-9bed87a55437
makeWaveMan(0, 0)
# ╔═╡ fadc4de4-128f-4717-b10e-478650a89eb0
typeof(makeWaveMan(0, 0))
# ╔═╡ 852d557c-bd92-4408-8b6c-2e18cec1ff3e
plot(makeWaveMan(0, 0).body, layout=makeWaveMan(0, 0).layout, colour=:cornflowerblue, opacity=0.4, xlims=(-2,19), ylims=(0, 23), ratio=:equal, xlabel="X", ylabel="Y", label=false, title="makeWaveMan(0, 0).image")
# ╔═╡ aa5c9420-c0b2-407f-a2da-595e78503800
plot(makeWaveMan(0, 0, normalize=true).body, layout=makeWaveMan(0, 0, normalize=true).layout, colour=:cornflowerblue, label=false, legend=false, opacity=0.4, xlims=(-0.1, 1.1), ylims=(-0.1, 1.1), ratio=:equal, xlabel="X", ylabel="Y", title="makeWaveMan(0, 0, normalize=true).body")
# ╔═╡ 46027a5b-36e2-4538-8b24-f3bdafc2f625
makeWaveMan()
# ╔═╡ 7ddfcf3f-ee06-40ad-b87f-b8aab427327e
plot(makeWaveMan().body, layout=makeWaveMan().layout, xlims=(-1, 18), ylims=(0,22), colour=:cornflowerblue, opacity=0.4, linecolour=:cornflowerblue, ratio=:equal, legend=false, xlabel="x", ylabel="y", title="makeWaveMan().body")
# ╔═╡ b8c56544-77ee-4a9b-9c10-e696c0440c89
plot(makeWaveMan(normalize=true).body, layout=makeWaveMan().layout, xlims=(-0.1, 1.2), ylims=(-0.1, 1.2), colour=:cornflowerblue, opacity=0.4, linecolour=:cornflowerblue, ratio=:equal, legend=false, xlabel="x", ylabel="y", title="makeWaveMan(normalize=true).body")
# ╔═╡ acc2e14a-67d8-45a3-a585-09085fed2e2d
makeWaveMan()
# ╔═╡ bf095bf1-bf59-4aee-86cc-15e6505377f3
md"
---
#### 2.2.4.2 *transpilation* of SICP-chapter 2.2.4 with *idiomatic typed* Julia functions
"
# ╔═╡ 920ca7c2-c761-4bcd-ab8e-9dd9897c575b
md"
---
##### 2.2.4.2.1 Basics
"
# ╔═╡ fc243a78-4679-4a34-a7b3-50daff85fe30
list(xs::Any...)::Array = [xs::Any...]::Array
# ╔═╡ 1a4784b2-9699-4145-a990-3b6f8ee18d42
FloatOrSigned = Union{AbstractFloat, Signed}
# ╔═╡ fa6a303a-4929-4536-83ea-8d0df9a92320
md"
###### Exercise 2.46: *constructor* and *selectors* for vectors of type '*Vect*'
"
# ╔═╡ 47425a32-bee9-4067-8a83-6232c9a78e19
struct Vect
x::FloatOrSigned
y::FloatOrSigned
end
# ╔═╡ 2afa5704-34aa-4ef7-b922-a4361526e81f
makeVect(x::FloatOrSigned, y::FloatOrSigned) = Vect(x, y)
# ╔═╡ 31d6aba9-2f4f-4562-8344-15cb1f6d1176
xcorVect(v::Vect)::FloatOrSigned = v.x
# ╔═╡ ede8e63c-8063-49d7-8a2d-d71cf943b7ac
ycorVect(v::Vect)::FloatOrSigned = v.y
# ╔═╡ 1559f2dd-90c5-49ba-b8e7-9c1f5aadb667
addVect(v1::Vect, v2::Vect) = makeVect(v1.x + v2.x, v1.y + v2.y)
# ╔═╡ 41d9b94b-d3c8-42d5-ae34-de447726054a
subVect(v1::Vect, v2::Vect) = makeVect(v1.x - v2.x, v1.y - v2.y)
# ╔═╡ b9b5bc3f-a3f8-4d6f-ae1f-364cc33b9583
scaleVect(s::FloatOrSigned, v::Vect) = makeVect(s * v.x, s * v.y)
# ╔═╡ f8e414a2-105c-4865-b25b-57ded04d2468
makeVect(0, 0)
# ╔═╡ 498e7c79-dfef-4448-8cc0-e6022b145110
makeVect(0, 0).x
# ╔═╡ d55945d3-2dc2-478a-b639-09b5fdd35d24
makeVect(0, 0).y
# ╔═╡ bab0efeb-5bda-48b0-bc65-5db529d71753
md"
---
##### 2.2.4.2.2 Frames
"
# ╔═╡ 08b351c8-0205-4ad7-a1d9-4092f4b419e2
md"
###### Exercise 2.47: *constructor* and *selectors* for frames of type '*Frame*'
"
# ╔═╡ 58340172-ccac-4c38-bbac-3de63e2898f8
struct Frame
origin::Vect
edge1::Vect
edge2::Vect
end
# ╔═╡ 0e88e7e2-7dda-4b0e-9496-1cf6e1511595
function makeFrame(;origin::Vect, edge1::Vect, edge2::Vect)::Frame
Frame(origin, edge1, edge2)
end
# ╔═╡ 8ce3b43f-1d8c-4b4b-8a50-e5c99aa27b9a
origin(frame::Frame)::Vect = frame.origin
# ╔═╡ b2f33856-939e-4830-aabe-33853036957c
edge1(frame::Frame)::Vect = frame.edge1
# ╔═╡ f1b6240d-8212-4e19-be8f-78148266c181
edge2(frame::Frame)::Vect = frame.edge2
# ╔═╡ 49192d52-b3bb-46e0-b88e-2b6047998b00
function frameCoordMap(frame)
function (vect) # 'vect' is vector to be mapped into the frame basis
addVect(
origin(frame),
addVect(scaleVect(xcorVect(vect), edge1(frame)),
scaleVect(ycorVect(vect), edge2(frame))))
end
end
# ╔═╡ 88026c63-bc23-46eb-8b34-ed5b41a990c2
frame1 = makeFrame(origin=Vect(2, 1), edge1=Vect(4, 4), edge2=Vect(0, 2))
# ╔═╡ d161baef-a8e4-4055-b80b-5d14daf040a1
origin(frame1)
# ╔═╡ 0aaf6909-38fc-4e1a-bfe4-c1739b55648d
edge1(frame1)
# ╔═╡ 600f7c1d-4f43-40b7-8b55-eef40de023a2
edge2(frame1)
# ╔═╡ 9bbe1659-18e8-4821-a2d6-73b25ccb31e6
frameCoordMap(frame1)(makeVect(0, 0))
# ╔═╡ 008b1e20-0dd0-49e7-953c-0aba79871488
frameCoordMap(frame1)(makeVect(1, 1))
# ╔═╡ e707b99b-2331-47ef-98f6-15d9f28c4ce7
frameCoordMap(frame1)(makeVect(0, 0)) == origin(frame1)
# ╔═╡ aaa0c0a9-0830-447a-af24-757c6e6186b1
md"
###### unit square $$P_{F_I}$$ *mapped* into *frame* '*makeFrame(origin=Vect(2, 1), edge1=Vect(3, 2), edge2=Vect(0, 3))*' and ...
###### ... red picture point $$p'_{F_I} = [1/2, 1/2]'$$ *mapped* into the above generated 'frame' as $$p_I$$.
"
# ╔═╡ 4669fb6f-3df2-445d-beb6-07695d2cc335
begin
plot([frameCoordMap(frame1)(makeVect(0, 0)).x, frameCoordMap(frame1)(makeVect(0, 1)).x, frameCoordMap(frame1)(makeVect(1, 1)).x, frameCoordMap(frame1)(makeVect(1, 0)).x, frameCoordMap(frame1)(makeVect(0, 0)).x],
[frameCoordMap(frame1)(makeVect(0, 0)).y, frameCoordMap(frame1)(makeVect(0, 1)).y, frameCoordMap(frame1)(makeVect(1, 1)).y, frameCoordMap(frame1)(makeVect(1, 0)).y, frameCoordMap(frame1)(makeVect(0, 0)).y], legend=false, xlims=(0, 7), ylims=(0, 7), ratio=:equal)
#--------------------------------------------------------------------------------
plot!([frameCoordMap(frame1)(makeVect(0.5, 0.5)).x], [frameCoordMap(frame1)(makeVect(0.5, 0.5)).y], markershape=:circle, markersize=3,markercolor=:red)
#--------------------------------------------------------------------------------
annotate!([(3.5, 3.6, ("p_C", 10, :bottom, :blue))])
plot!([(0, 0), (2, 1)], line = (:solid, :arrow, 0.8, 2, :red)) # origin vector
plot!([(2, 1), (2+4, 1+4)], line = (:solid, :arrow, 0.8, 2, :red)) # vect1
plot!([(2, 1), (2+0, 1+2)], line = (:solid, :arrow, 0.8, 2, :red)) # vect2
annotate!([(1.0, 0.4, ("frame origing vector", 10, :bottom, :blue))])
annotate!([(4.2, 2.5, ("frame edge vector v1", 10, :bottom, :blue))])
annotate!([(0.3, 1.8, ("frame edge vector v2", 10, :bottom, :blue))])
end
# ╔═╡ 7d81de72-094c-4c56-a7e1-80970050405b
function showFrame(frame::Frame)
let origin = frame.origin,
edge1 = frame.edge1,
edge2 = frame.edge2,
edge3 = addVect(edge1, edge2)
#------------------------------------------------------------------------
xs = vcat(origin.x, origin.x+edge1.x, origin.x+edge3.x, origin.x+edge2.x, origin.x)
ys = vcat(origin.y, origin.y+edge1.y, origin.y+edge3.y, origin.y+edge2.y, origin.y)
#------------------------------------------------------------------------
Shape(xs, ys)
end
end
# ╔═╡ 6ee6d67b-0d3e-4e0e-977c-0069531627ee
showFrame(frame1)
# ╔═╡ 6bfb76c4-5a50-4844-9cdd-f39e3c118ded
md"
###### *shape* of frame '*makeFrame(origin=Vect(2, 1), edge1=Vect(3, 2), edge2=Vect(0, 3))*'
"
# ╔═╡ 8d0c08c9-4635-4750-9675-b84ba0727859
begin
plot(showFrame(frame1), xlims=(0, 7), ylims=(0, 7), opacity=0.3, colour=:cornflowerblue, legend=false, ratio=:equal)
#--------------------------------------------------------------------------------
plot!([frameCoordMap(frame1)(makeVect(0.5, 0.5)).x], [frameCoordMap(frame1)(makeVect(0.5, 0.5)).y], markershape=:circle, markersize=3,markercolor=:red)
#--------------------------------------------------------------------------------
annotate!([(3.5, 3.6, ("p_C", 10, :bottom, :blue))])
plot!([(0, 0), (2, 1)], line = (:solid, :arrow, 0.8, 2, :red)) # origin vector
plot!([(2, 1), (2+4, 1+4)], line = (:solid, :arrow, 0.8, 2, :red)) # vect1
plot!([(2, 1), (2+0, 1+2)], line = (:solid, :arrow, 0.8, 2, :red)) # vect2
annotate!([(1.0, 0.4, ("frame origing vector", 10, :bottom, :blue))])
annotate!([(4.2, 2.5, ("frame edge vector v1", 10, :bottom, :blue))])
annotate!([(0.3, 1.8, ("frame edge vector v2", 10, :bottom, :blue))])
end
# ╔═╡ 96101227-2364-402d-bc15-4b74757df595
md"
###### *shape* of unit frame *projected* into frame '*makeFrame(origin=Vect(2, 1), edge1=Vect(3, 2), edge2=Vect(0, 3))*'
"
# ╔═╡ e29fea38-4a22-4b30-ab51-9e6bac1aae8d
begin
plot(Shape([frameCoordMap(frame1)(makeVect(0, 0)).x, frameCoordMap(frame1)(makeVect(0, 1)).x, frameCoordMap(frame1)(makeVect(1, 1)).x, frameCoordMap(frame1)(makeVect(1, 0)).x, frameCoordMap(frame1)(makeVect(0, 0)).x],
[frameCoordMap(frame1)(makeVect(0, 0)).y, frameCoordMap(frame1)(makeVect(0, 1)).y, frameCoordMap(frame1)(makeVect(1, 1)).y, frameCoordMap(frame1)(makeVect(1, 0)).y, frameCoordMap(frame1)(makeVect(0, 0)).y]), opacity=0.3, colour=:cornflowerblue, legend=false, xlims=(0, 7), ylims=(0, 7), ratio=:equal)
#--------------------------------------------------------------------------------
plot!([frameCoordMap(frame1)(makeVect(0.5, 0.5)).x], [frameCoordMap(frame1)(makeVect(0.5, 0.5)).y], markershape=:circle, markersize=3,markercolor=:red)
#--------------------------------------------------------------------------------
annotate!([(3.5, 3.6, ("p_C", 10, :bottom, :blue))])
plot!([(0, 0), (2, 1)], line = (:solid, :arrow, 0.8, 2, :red)) # origin vector
plot!([(2, 1), (2+4, 1+4)], line = (:solid, :arrow, 0.8, 2, :red)) # vect1
plot!([(2, 1), (2+0, 1+2)], line = (:solid, :arrow, 0.8, 2, :red)) # vect2
annotate!([(1.0, 0.4, ("frame origing vector", 10, :bottom, :blue))])
annotate!([(4.2, 2.5, ("frame edge vector v1", 10, :bottom, :blue))])
annotate!([(0.3, 1.8, ("frame edge vector v2", 10, :bottom, :blue))])
end
# ╔═╡ 8bcefd49-ab7b-4dc1-bfef-d7349a91bc46
md"
---
##### 2.2.4.2.3 Painters
"
# ╔═╡ a70ff6fe-0b70-4661-91b0-509ebeb43756
md"
###### Exercise 2.48: *constructor* and *selectors* of segments of type 'Segment'
"
# ╔═╡ 04e0f2fd-29b0-427c-bcb9-597c32feb44d
struct Segment
startPoint::Vect
endPoint::Vect
end
# ╔═╡ e845c43d-7bc9-40f4-836e-d00f37ee1f3d
function makeSegment(startP::Vect, endP::Vect)::Segment
Segment(startP, endP)
end
# ╔═╡ e52e9f54-5e8c-4d58-869d-23c126e07d21
function startSegment(segment::Segment)::Vect
segment.startPoint
end
# ╔═╡ 30f40e44-0017-47cd-bc86-904207ab13c1
function endSegment(segment::Segment)::Vect
segment.endPoint
end
# ╔═╡ 4b277624-ee34-4c53-8c45-6a9d3a0520b4
function showSegment(segment::Segment)
let startP = segment.startPoint,
endP = segment.endPoint
#-------------------------------------------------------
xs = vcat(startP.x, endP.x)
ys = vcat(startP.y, endP.y)
#-------------------------------------------------------
Shape(xs, ys)
end
end
# ╔═╡ f599491e-d319-4fd4-93fc-13260ef1994b
md"
###### example: 4 segments
"
# ╔═╡ 5c155953-505d-4aa8-b0b5-f5d6df47104d
begin
segment1 = makeSegment(makeVect(2, 1), makeVect(5, 3))
segment2 = makeSegment(makeVect(5, 3), makeVect(5, 6))
segment3 = makeSegment(makeVect(5, 6), makeVect(2, 4))
segment4 = makeSegment(makeVect(2, 4), makeVect(2, 1))
segmentList = list(segment1, segment2, segment3, segment4)
end
# ╔═╡ bba021f1-caf8-48ef-967c-1c7dde6464cf
plot([showSegment(segment) for segment in segmentList], legend=false, xlims=(0, 7), ylims=(0, 7), ratio=:equal, linewidth=4, opacity=0.4, linecolour=:cornflowerblue)
# ╔═╡ db55e00e-9056-442e-876f-1e39f014b0c7
md"
###### Two *methods* of function 'drawline' ...
###### ... the *first* for only *one* segment
"
# ╔═╡ 8d94c9ef-8821-4054-9a0b-0cb72abb50e2
function drawLine(segment::Segment; axis=false, xlims=(0.0, 1.0), ylims=(0.0, 1.0), legend=false, showaxis=false)
#------------------------------------------------------------------------------
plot()
#------------------------------------------------------------------------------
plot!(showSegment(segment), axis=axis, xlims=xlims, ylims=ylims, linewidth=4, opacity=0.4, linecolour=:cornflowerblue, legend=legend, ratio=:equal, showaxis=showaxis)
end
# ╔═╡ 0066351b-a86b-4be0-8ff9-f479a26ff699
md"
###### ... the *second* for a *list* (= array) of segments
"
# ╔═╡ b7aa0a8f-2c8b-4ff2-8efe-5b88b0009700
#=
===== this simple sketch with *foreach(....)* does not display an image - for whatever reason -
function drawLine(segmentList::Array; xlims=(0.0, 1.0), ylims=(0.0, 1.0), legend=false, axis=false)
#------------------------------------------------------------------------------
plot()
#------------------------------------------------------------------------------
foreach(segment -> plot!(segment, xlims=xlims, ylims=ylims, linewidth=4, opacity=0.4, linecolour=:cornflowerblue, legend=legend, ratio=:equal, axis=axis), segmentList)
=#
# ╔═╡ 24a99293-215f-4b10-bdde-dd3765679704
function drawLine(segmentList::Array; axis=false, legend=false,ratio=:equal, showaxis=false, xlims=(0.0, 1.0), ylims=(0.0, 1.0))
#------------------------------------------------------------------------------
function showSegments(segmentList)
map(segment -> showSegment(segment), segmentList)
end
#------------------------------------------------------------------------------
plot()
#------------------------------------------------------------------------------
plot!(showSegments(segmentList), axis=axis, xlims=xlims, ylims=ylims, linewidth=4, opacity=0.4, linecolour=:cornflowerblue, legend=legend, ratio=ratio)
end
# ╔═╡ c789fabd-076e-4c87-9e00-061247e41e76
drawLine(segmentList, axis=true, xlims=(0, 7), ylims=(0, 7))
# ╔═╡ 90aa8c1e-1eae-42d9-b71e-3c58a1c1169c
drawLine(segmentList, xlims=(0, 7), ylims=(0, 7), axis=true)
# ╔═╡ 029f90e8-cbd1-482c-b553-9f068bf13a48
md"
###### Vectors of 'wave' *coordinates*
"
# ╔═╡ fa14cfef-1dac-4f6f-9176-a48bfd1096ee
waveX = makeWaveMan(0, 0, normalize=true).body.x
# ╔═╡ f02ec249-22ef-4134-bf29-e7c109e2e28b
waveY = makeWaveMan(0, 0, normalize=true).body.y
# ╔═╡ b07f1822-0fe9-4e93-b16f-79e42eb602b2
scatter(waveX, waveY, ratio=:equal, xlims=(-0.1, 1.1), ylims=(-0.1, 1.1))
# ╔═╡ a827e2b0-94dc-4474-87c6-809097827fe5
plot(waveX, waveY, colour=:cornflowerblue, legend=false, ratio=:equal, xlims=(-0.1, 1.1), ylims=(-0.1, 1.1))
# ╔═╡ 760980ad-84e0-4b08-851a-2fa717197d1e
function makeVects(xs, ys)
map((x, y) -> makeVect(x, y),xs, ys)
end
# ╔═╡ 5afab965-e8d4-41d1-865c-a864533ac4f6
md"
###### Sequence of 'wave' *points*
"
# ╔═╡ 983cab48-d122-4b72-a187-c0226ea7171a
waveVects = makeVects(makeWaveMan(0, 0, normalize=true).body.x, makeWaveMan(0, 0, normalize=true).body.y)
# ╔═╡ 3f03377b-9869-4f89-9b47-2fa011ca9133
md"
###### Make *segmentList* of an array of 2-dim *vectors* (= points)
"
# ╔═╡ cd7a669c-bd12-4d91-8ea0-f52001d93b2b
function makeSegments(vectXsYsSeq; normalize=false)
if normalize !== false
# normalize all segments so that the segemntList (= figure) lays inside a unit square
maxX = maximum(vect -> vect.x, vectXsYsSeq)
minX = minimum(vect -> vect.x, vectXsYsSeq)
maxY = maximum(vect -> vect.y, vectXsYsSeq)
minY = minimum(vect -> vect.y, vectXsYsSeq)
lengthX = maxX - minX
lengthY = maxY - minY
vectXsYsSeq2X = [(vect.x - minX) / lengthX for vect in vectXsYsSeq]
vectXsYsSeq2Y = [(vect.y - minY) / lengthY for vect in vectXsYsSeq]
vectXsYsSeq3 = map((x, y) -> makeVect(x, y), vectXsYsSeq2X, vectXsYsSeq2Y)
#-------------------------------------------------------------------------
else
vectXsYsSeq3 = vectXsYsSeq
end # if
segmentList = [makeSegment(vectXsYsSeq3[i], vectXsYsSeq3[i+1]) for i in 1:length(vectXsYsSeq3)-1]
segmentList
end
# ╔═╡ 4fa6484f-c5d9-4008-abb1-e52a3d86fa7f
md"
###### *normalized* original figure 'wave' (= image) lays in the *unit* square
"
# ╔═╡ 8db80004-fe6a-4011-b382-cb5e5b2d6522
md"
###### *normalized* figure 'wave' (= image) lays in the *unit* square
"
# ╔═╡ a1cc0260-eb3f-4963-a39a-e9f77b5e5ffe
drawLine(makeSegments(waveVects, normalize=true), axis=true, xlims=(-0.05, 1.05), ylims=(-0.05, 1.05))
# ╔═╡ bec7ad15-e052-4112-a06d-0fff4760118f
plot(Shape(waveX, waveY), colour=:cornflowerblue, legend=false, opacity=0.4, ratio=:equal, xlims=(-0.01, 1.01), ylims=(-0.01, 1.01))
# ╔═╡ d261a419-5d4f-4f83-9132-e13ad706ca94
md"
###### 'waveMan' mapped (= projected) into basis (= frame)
"
# ╔═╡ d1e95027-c3b1-4590-be8b-a7a0f3252abb
md"
###### higher order *method* (= *handler*) 'segmentsToPainter' of SICP-function 'segments->painter'
"
# ╔═╡ a0928969-8fa1-42b3-ace5-ae2a9fd9685f
function segmentsToPainter(segmentList; axis=false, legend=false, xlims=(0, 1), ylims=(0, 1), ratio=:equal, showaxis=false, ticks=false)
function(frame) # anonymous (lambda) function
segmentsToPlot =
map(segment ->
makeSegment(
frameCoordMap(frame)(startSegment(segment)),
frameCoordMap(frame)(endSegment(segment))), segmentList)
end # anonymous (lambda) function with argument 'frame'
end
# ╔═╡ 79cfbc47-86b1-4250-a05c-d21d8c50532c
segmentsToPainter(segmentList, axis=true, xlims=(0, 40), ylims=(0, 40), showaxis=true, ticks=true)(frame1)
# ╔═╡ 1b9183ea-f236-4a50-a35d-d47e6e7c1249
begin
drawLine(segmentsToPainter(makeSegments(waveVects, normalize=true))(frame1), axis=true, xlims=(0, 7), ylims=(0, 6))
#--------------------------------------------------------------------------------
plot!([frameCoordMap(frame1)(makeVect(0.5, 0.5)).x], [frameCoordMap(frame1)(makeVect(0.5, 0.5)).y], markershape=:circle, markersize=2, markercolor=:red)
#--------------------------------------------------------------------------------
plot!([(0, 0), (2, 1)], line = (:solid, :arrow, 0.4, 2, :red)) # origin vector
plot!([(2, 1), (2+4, 1+4)], line = (:solid, :arrow, 0.4, 1, :red)) # vect1
plot!([(2, 1), (2+0, 1+2)], line = (:solid, :arrow, 0.4, 1, :red)) # vect2
end
# ╔═╡ 2fd64aea-95fb-431b-935e-527f5aaba8d8
md"
###### *variation* 'shapeToPainter' of higher order *method* (= *handler*) of SICP-function 'segments->painter'
"
# ╔═╡ f827ca99-414c-4e94-ae3d-6fbf3de57c4b
function shapeToPainter(shapeList::Shape; axis=false, legend=false, xlims=(0, 1), ylims=(0, 1), ratio=:equal, showaxis=false, ticks=false)
function(frame) # anonymous (lambda) function
shapeToPlot =
map((x, y) -> frameCoordMap(frame)(makeVect(x, y)), shapeList.x, shapeList.y)
xs = map(vect -> vect.x, shapeToPlot)
ys = map(vect -> vect.y, shapeToPlot)
Shape(xs, ys)
end # anonymous (lambda) function with argument 'frame'
end # function
# ╔═╡ 08fc8b77-4635-4f44-b8ae-5fc0e0171237
makeWaveMan(0, 0, normalize=true).body
# ╔═╡ 341567d3-7025-4cda-8385-72dea3d292bb
plot(makeWaveMan(0, 0, normalize=true).body, colour=:cornflowerblue, legend=false, opacity=0.4, ratio=:equal, xlims=(-0.1, 1.1), ylims=(-0.1, 1.1))
# ╔═╡ e787150f-f7eb-4b9e-8a16-67b93d4ac446
shapeToPainter(makeWaveMan(0, 0, normalize=true).body)(frame1)
# ╔═╡ 61793d34-cac1-4661-9d47-459b31525eba
shapeToPainter(makeWaveMan(0, 0, normalize=true).body)(frame1).x
# ╔═╡ 70d70ded-1514-443d-9215-7da991172c8e
shapeToPainter(makeWaveMan(0, 0, normalize=true).body)(frame1).y
# ╔═╡ ca5e45e9-63c9-4747-bcab-f325a2e2f4a8
# shapeToPainter works with *lines* and with *shapes*. *here* with *lines*
begin
plot(shapeToPainter(makeWaveMan(0, 0, normalize=true).body)(frame1).x, shapeToPainter(makeWaveMan(0, 0, normalize=true).body)(frame1).y, colour=:cornflowerblue, legend=false, xlims=(0, 7), ylims=(0, 7), ratio=:equal)
#-----------------------------------------------------------------------------
plot!([(0, 0), (2, 1)], line = (:solid, :arrow, 0.4, 2, :red)) # origin vector
plot!([(2, 1), (2+4, 1+4)], line = (:solid, :arrow, 0.4, 1, :red)) # vect1
plot!([(2, 1), (2+0, 1+2)], line = (:solid, :arrow, 0.4, 1, :red)) # vect2
end
# ╔═╡ 01377420-6d54-4856-b6b6-e919b1ce55a3
begin
# shapeToPainter works with *lines* and with *shapes*. *here* with *shape*
plot(shapeToPainter(makeWaveMan(0, 0, normalize=true).body)(frame1), colour=:cornflowerblue, legend=false, opacity=0.4, xlims=(0, 7), ylims=(0, 7), ratio=:equal)
#-----------------------------------------------------------------------------
plot!([(0, 0), (2, 1)], line = (:solid, :arrow, 0.4, 2, :red)) # origin vector
plot!([(2, 1), (2+4, 1+4)], line = (:solid, :arrow, 0.4, 1, :red)) # vect1
plot!([(2, 1), (2+0, 1+2)], line = (:solid, :arrow, 0.4, 1, :red)) # vect2
end
# ╔═╡ ed6942c0-7334-4932-9eb7-72ef41d5c2ac
plot(shapeToPainter(makeWaveMan(0, 0, normalize=true).body)(frame1).x, shapeToPainter(makeWaveMan(0, 0, normalize=true).body)(frame1).y, colour=:cornflowerblue, legend=false, xlims=(2, 6), ylims=(2, 6), ratio=:equal)
# ╔═╡ 083e2d1c-754f-416a-84e5-d0ab6be6fb1e
begin
plot(shapeToPainter(makeWaveMan(0, 0, normalize=true).body)(frame1).x, shapeToPainter(makeWaveMan(0, 0, normalize=true).body)(frame1).y, colour=:cornflowerblue, legend=false, xlims=(2, 6), ylims=(2, 6), ratio=:equal)
plot!(shapeToPainter(makeWaveMan(0, 0, normalize=true).mouth)(frame1), colour=:cornflowerblue, legend=false, opacity=0.4, xlims=(2, 6), ylims=(2, 6), ratio=:equal)
plot!(shapeToPainter(makeWaveMan(0, 0, normalize=true).nose)(frame1), colour=:cornflowerblue, legend=false, opacity=0.4, xlims=(2, 6), ylims=(2, 6), ratio=:equal)
plot!(shapeToPainter(makeWaveMan(0, 0, normalize=true).leftEye)(frame1), colour=:cornflowerblue, legend=false, opacity=0.4, xlims=(2, 6), ylims=(2, 6), ratio=:equal)
plot!(shapeToPainter(makeWaveMan(0, 0, normalize=true).rightEye)(frame1), colour=:cornflowerblue, legend=false, opacity=0.4, xlims=(2, 6), ylims=(2, 6), ratio=:equal)
end
# ╔═╡ ac1abf65-71a3-4c61-9966-c0586209913f
# shapeToPainter works with *lines* and with *shapes*. *here* with *shape*
plot(shapeToPainter(makeWaveMan(0, 0, normalize=true).body)(frame1), colour=:cornflowerblue, legend=false, opacity=0.4, xlims=(2, 6), ylims=(2, 6), ratio=:equal)
# ╔═╡ 0c33236a-8988-4056-b591-e1df74b8a5cc
begin
# shapeToPainter works with *lines* and with *shapes*. *here* with *shape*
plot(shapeToPainter(makeWaveMan(0, 0, normalize=true).body)(frame1), colour=:cornflowerblue, legend=false, opacity=0.4, xlims=(2, 6), ylims=(2, 6), ratio=:equal)
plot!(shapeToPainter(makeWaveMan(0, 0, normalize=true).mouth)(frame1), colour=:cornflowerblue, legend=false, opacity=0.4, xlims=(2, 6), ylims=(2, 6), ratio=:equal)
plot!(shapeToPainter(makeWaveMan(0, 0, normalize=true).nose)(frame1), colour=:cornflowerblue, legend=false, opacity=0.4, xlims=(2, 6), ylims=(2, 6), ratio=:equal)
plot!(shapeToPainter(makeWaveMan(0, 0, normalize=true).leftEye)(frame1), colour=:cornflowerblue, legend=false, opacity=0.4, xlims=(2, 6), ylims=(2, 6), ratio=:equal)
plot!(shapeToPainter(makeWaveMan(0, 0, normalize=true).rightEye)(frame1), colour=:cornflowerblue, legend=false, opacity=0.4, xlims=(2, 6), ylims=(2, 6), ratio=:equal)
end
# ╔═╡ 66554a9f-e380-4835-8ee4-8affc094aa6d
md"
---
#### 2.2.4.3 SICP-chapter 2.2.4 with *linear algebra* Julia functions
"
# ╔═╡ fbd4007c-d25d-4257-abee-779fa40ba3b5
md"
###### [Matrix Representation](https://mml-book.github.io/book/mml-book.pdf) of the *Higher-order* Function '*frameCoordMap*'
Function '*frameCoordMap*' expects as the *only* arguments a *frame* (= *basis*) $$\mathbf F_C$$ and an additive *origin* $$\mathbf O_C$$. The space of the *frame* is generated by the *column space* (Strang, 2019) of $$\mathbf F_C$$ and the *origin* $$\mathbf O_C$$.
As a result '*frameCoordMap*' generates an *anonymous* function which expects as argument a *column vector* $$\mathbf g_{F_C} \in \mathbf G_{F_C}$$ representing a *graphics point* which was generated by a graphics function and which has to be mapped to a *plot point* $$\mathbf p_I$$. $$\mathbf p_I$$ is the output of the anonymous function.
The *graphics pont* $$\mathbf g_{F_C}$$ is expected to stem from the a *unit square* graphics board: $$\mathbf g_{F_C} \in [0, 1] \times [0, 1]$$. Only then it is guaranteed that its map the *plot point* $$\mathbf p_C$$ lays within certain boundaries of the *plot area* generated by the column space of $$\mathbf P_C$$.
The coordinates of $$\mathbf G_{F_C}$$'s column vectors are *relative* to the *frame* basis $$\mathbf F_C$$. The output of '*frameCoordMap*' is a transformed or mapped vector $$\mathbf p_C \in \mathbf P_C$$. Its coordinates are *relative* to the *cartesian* basis $$\mathbf I_C$$. The *mapped* vector $$\mathbf p_C$$ lays within the *mapped* unit square *relative* to the basis $$\mathbf I_C$$. The mapping can be denoted by a simple *matrix equation*:
"
# ╔═╡ d7254951-2d3e-4c29-a0c3-e91478bde859
md"
$$\mathbf F_C \cdot \mathbf G_{F_C} + \mathbf O_C = \mathbf I_C \cdot \mathbf G_C + \mathbf O_C = \mathbf G_C + \mathbf O_C = \mathbf P_C.$$
where:
$$\mathbf F_C \text{ = matrix with column space establishing the nonorthogonal and nonshifted ...}$$
$$\text{... basis of 'frame' with coordinates relative to the classical cartesian basis } \mathbf I_C.$$
$$\mathbf G_{F_C} \text{ = matrix with column vectors representing normalized graphics points ...}$$
$$\text{... with coordinates relative to the 'frame' basis } \mathbf F_C.$$
$$\mathbf O_C \text{ = matrix with column vectors representing the origin of the 'frame' ...}$$
$$\text{ ... with coordinates relative to the classical cartesian basis }\mathbf I_C.$$
$$\mathbf I_C \text{ = matrix with unit column vectors establishing ...}$$
$$\text{... the orthogonal nonshifted classical cartesian basis } \mathbf C.$$
$$\mathbf G_C \text{ = matrix with column vectors representing unnormalized nonshifted mapped ...}$$
$$\text{... graphic points with coordinates relative to the cartesian basis } \mathbf I_C.$$
$$\mathbf P_C \text{ = matrix with column vectors representing shifted mapped graphic points ...}$$
$$\text{... ready to be plotted with coordinates relative to the cartesian basis } \mathbf I_C.$$
"
# ╔═╡ 056e907d-47a8-4c61-8151-562d6c923802
md"
Here we present a numerical example:
$$% outer vertical array of arrays
\begin{array}{ccc} % outer array
\\
% inner array of basis F_C values relative to cartesian basis I_C
\begin{array}{c|cc}
\mathbf F_C & v1 & v2 \\
\hline
x & 4 & 0 \\
y & 4 & 2 \\
\hline
\end{array}% end of F_C
&
\cdot
&
% inner array of unit square values relative to basis F_C
\begin{array}{c|cccc}
\mathbf G_{F_C} & g1_{F_C} & g2_{F_C} & g3_{F_C} & g4_{F_C} \\
\hline
v1 & 0 & 1 & 1 & 0\\
v2 & 0 & 0 & 1 & 1\\
\hline
\end{array}% end of G_{F_C}
&
+
&
% inner array of origin values relative to basis I_C
\begin{array}{c|cccc}
\mathbf O_C & g1_{F_C} & g2_{F_C} & g3_{F_C} & g4_{F_C} \\
\hline
x & 2 & 2 & 2 & 2 \\
y & 1 & 1 & 1 & 1 \\
\hline
\end{array}% end of O_C
&
=
\\
\\
% inner array of basis I_C values
\begin{array}{c|cc}
\mathbf I_C & v1 & v2 \\
\hline
x & 1 & 0 \\
y & 0 & 1 \\
\hline
\end{array}% end of I_C
&
\cdot
&
% inner array of mapped unit square values relative to basis I_C
\begin{array}{c|cccc}
\mathbf G_C & g1_C & g2_C & g3_C & g4_C \\
\hline
v1 & 0 & 4 & 4 & 0 \\
v2 & 0 & 4 & 6 & 2 \\
\hline
\end{array}% end of G_C
&
+
&
% inner array of origin values relative to basis I_C
\begin{array}{c|cccc}
\mathbf O_C & g1_C & g2_C & g3_C & g4_C \\
\hline
x & 2 & 2 & 2 & 2 \\
y & 1 & 1 & 1 & 1 \\
\hline
\end{array}% end of O_C
&
=
\\
\\
&
&
% inner array of plot points values relative to basis I
\begin{array}{c|cccc}
\mathbf P_C & p1_C & p2_C & p3_C & p4_C \\
\hline
x & 2 & 6 & 6 & 2 \\
y & 1 & 5 & 7 & 3 \\
\hline
\end{array}% end of P_C
\\
\\
\end{array} % outer array$$
The last matrix $$\mathbf P_C$$ can be plotted by e.g. Julia's Plot backend. The components of all column vectors are relative to the classical cartesian basis $$\mathbf C$$.
"
# ╔═╡ 1bd58db9-bfde-4486-8525-91c6708cadea
F_C = # frame matrix (= basis)
[edge1(frame1).x edge2(frame1).x;
edge1(frame1).y edge2(frame1).y]
# ╔═╡ 84e519f4-f10c-4625-a816-72650b3f47db
G_F_C = [0 1 1 0; 0 0 1 1]
# ╔═╡ c2cb7097-c076-4749-962b-a2625704ffd1
O_C =
[origin(frame1).x origin(frame1).x origin(frame1).x origin(frame1).x;
origin(frame1).y origin(frame1).y origin(frame1).y origin(frame1).y]
# ╔═╡ 2f2eb3e9-21ee-45cb-96ff-1530e4386ec0
G_C = F_C * G_F_C
# ╔═╡ 3204f3c0-657f-4fb0-88e3-59daf5c5a6f5
left = F_C * G_F_C + O_C
# ╔═╡ 10673915-519e-4e99-b933-5221bdcd04e3
I_C = [1 0; 0 1]
# ╔═╡ 276c7428-6920-4c55-8ca4-b0cea410e11f
P_C = I_C * G_C + O_C
# ╔═╡ e4b79b33-fbfb-4d31-b560-8cd4c71b520a
left == P_C
# ╔═╡ 06f46732-5984-40fe-8651-8139e5c97be2
md"
$$\mathbf F_C \cdot \mathbf G_{F_C} + \mathbf O_C = \mathbf I_C \cdot \mathbf G_C + \mathbf O_C = \mathbf G_C + \mathbf O_C = \mathbf P_C.$$
Now, we want to map *one* graphic point $$\mathbf g_{F_C}=[0.5, 0.5] \mapsto \mathbf p_C=[4.0, 4.0]$$
$$% outer vertical array of arrays
\begin{array}{ccccccc} % outer array
&
% inner array of basis B_C values relative to cartesian Basis I_C
\begin{array}{c|cc}
\mathbf F_C & v1 & v2 \\
\hline
x & 4 & 0 \\
y & 4 & 2 \\
\hline
\end{array}% end of F_C
&
\cdot
&
% inner array of graphic point values relative to basis F_C
\begin{array}{c|c}
\mathbf g_{F_C} & g1_{F_C}\\
\hline
v1 & 0.5\\
v2 & 0.5\\
\hline
\end{array}% end of g_{F_C}
&
+
&
% inner array of origin point values relative to basis I
\begin{array}{c|c}
\mathbf o_C & g1_{F_C}\\
\hline
x & 2\\
y & 1\\
\hline
\end{array}% end of o_C
&
=
\\
\\
&
% inner array of basis I values
\begin{array}{c|cc}
\mathbf I_C & v1 & v2\\
\hline
x & 1 & 0\\
y & 0 & 1\\
\hline
\end{array}% end of I_C
&
\cdot
&
% inner array of mapped graphic point values relative to basis I
\begin{array}{c|c}
\mathbf g_C & g1_C \\
\hline
v1 & 2.0 \\
v2 & 3.0 \\
\hline
\end{array}% end of g_C
&
+
&
% inner array of origin point values relative to basis I
\begin{array}{c|c}
\mathbf o_C & g1_C \\
\hline
x & 2\\
y & 1\\
\hline
\end{array}% end of o_C
&
=
\\
\\
&
&
&
% inner array of mapped plot point values relative to basis I
\begin{array}{c|c}
\mathbf p_C& p1_C\\
\hline
x & 4.0 \\
y & 4.0 \\
\hline
\end{array}% end of p_C
\\
\end{array} % outer array$$
The plot point $$\mathbf p1_C$$ is the *red* point in the above plots.
"
# ╔═╡ 4508ef9d-2849-46f9-95bd-35b33f9009fb
g_F_C = [0.5; 0.5]
# ╔═╡ 9851e418-5a90-46b0-94ba-0af50f25ee44
g_C = F_C * g_F_C
# ╔═╡ 36b0caf5-6f89-4721-8df9-2cc9136088c5
o_C = [origin(frame1).x; origin(frame1).y]
# ╔═╡ 0d8a83d8-94f9-4bb6-92c3-6b8b2ee6773e
leftVect = F_C * g_F_C + o_C
# ╔═╡ 31c42c5b-f4a9-4a9e-8952-eca377b8f7c9
rightVect = I_C * g_C + o_C
# ╔═╡ 1c7e9ea4-fb38-4efb-834c-a7fded474490
F_C * g_F_C + o_C == I_C * g_C + o_C
# ╔═╡ 93f74238-dd20-416d-8c5f-b698a9c154aa
md"
The point $$\mathbf p_I = [4.0, 4.0]$$ is mapped as the *red* point in the above plots.
"
# ╔═╡ 1c341b70-17f3-437c-8199-8dc579bb415d
md"
---
##### References
- **Abelson, H., Sussman, G.J. & Sussman, J.**; Structure and Interpretation of Computer Programs, Cambridge, Mass.: MIT Press, (2/e), 1996, [https://sarabander.github.io/sicp/](https://sarabander.github.io/sicp/), last visit 2022/09/07
- **Deisenroth, M.P.; Faisal, A.A. & Ong, Ch.S.**; Mathematics For Machine Learning; Cambridge: Cambridge University Press, [https://mml-book.github.io/book/mml-book.pdf](https://mml-book.github.io/book/mml-book.pdf); visited 2022/09/07
- **Plotly**; [https://plotly.com/julia/getting-started/](https://plotly.com/julia/getting-started/); visited 2022/09/07
- **Strang, G.**; Linear Algebra and Learning From Data; Wellesley, MA: Wellesley - Cambridge Press, 2019
- **Wikipedia**; Closure (Computer Programming); [https://en.wikipedia.org/wiki/Closure_(computer_programming)](https://en.wikipedia.org/wiki/Closure_(computer_programming)); visited 2022/09/07
- **Wikipedia**; Closure (Mathematics); [https://en.wikipedia.org/wiki/Closure_(mathematics)](https://en.wikipedia.org/wiki/Closure_(mathematics)); visited 2022/09/07
"
# ╔═╡ c7a2fad9-36b4-4b0d-950b-0c01e3fa6bbb
md"
---
##### end of ch. 2.2.4
====================================================================================
This is a **draft** under the [Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](https://creativecommons.org/licenses/by-nc-sa/4.0/) license. Comments, suggestions for improvement and bug reports are welcome: **claus.moebus(@)uol.de**
===================================================================================
"
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
[compat]
Plots = "~1.27.3"
"""
# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised
julia_version = "1.8.0"
manifest_format = "2.0"
project_hash = "4019caac6ef07368b620a3190c549dd7efd90728"
[[deps.Adapt]]
deps = ["LinearAlgebra"]
git-tree-sha1 = "af92965fb30777147966f58acb05da51c5616b5f"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "3.3.3"
[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.1"
[[deps.Artifacts]]