Repository navigation
Expand file tree
/
Copy pathalgorithm.html
More file actions
1354 lines (1274 loc) · 56.9 KB
/
Copy pathalgorithm.html
File metadata and controls
1354 lines (1274 loc) · 56.9 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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>From plane to pixel — the projection algorithm, step by step</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Archivo:wght@500;600;700&family=IBM+Plex+Mono:wght@400;500;600&family=Newsreader:opsz,wght@6..72,400;6..72,500;6..72,600&display=swap" rel="stylesheet">
<!-- shared site styles: ../site/ when previewing from docs/, plain path on Pages -->
<link rel="stylesheet" href="../site/style.css">
<link rel="stylesheet" href="style.css">
<style>
:root {
--paper: #0d1411;
--ink: #e9efeb;
--ink-soft: #9aad9f;
--rule: #263429;
--panel: #121a16;
--panel-2: #17231d;
--panel-edge: #31423a;
--panel-ink: #e9efeb;
--panel-muted: #93a49a;
--accent: #63d0cf;
--accent-deep: #5fd2cf;
--danger: #ff8a7a;
--danger-deep: #a63a2e;
--c-top-left: #7e3fa6;
--c-top-right: #b24a12;
--c-bottom-left: #0b6b78;
--c-bottom-right: #4a6e20;
--c-top-left-d: #c99ae8;
--c-top-right-d: #f0a878;
--c-bottom-left-d: #6fd3df;
--c-bottom-right-d: #b5d68c;
--sans: "Archivo", "Helvetica Neue", Arial, sans-serif;
--serif: "Newsreader", Georgia, "Times New Roman", serif;
--mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
body {
margin: 0;
background: var(--paper);
color: var(--ink);
font: 400 17px/1.62 var(--serif);
-webkit-font-smoothing: antialiased;
}
main { max-width: 1120px; margin: 0 auto; padding: 3rem 1.5rem 5rem; }
p { max-width: 68ch; margin: 0 0 1rem; }
a { color: var(--accent-deep); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--ink); }
code {
font: 400 .86em/1.4 var(--mono);
background: rgba(233, 239, 235, .08);
padding: .08em .3em;
border-radius: 2px;
}
h2 {
font: 600 1.45rem/1.2 var(--sans);
letter-spacing: -.015em;
margin: 0 0 1rem;
}
section { margin-top: 3.8rem; }
:focus-visible { outline: 2px solid var(--accent-deep); outline-offset: 3px; }
.workbench :focus-visible { outline-color: var(--accent); }
/* ---- title sheet ---- */
.page-head {
display: grid;
grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr);
gap: 1.6rem 3rem;
align-items: end;
padding: 1.4rem 0 2.4rem;
border-top: 1px solid var(--ink);
border-bottom: 1px solid var(--rule);
background-image:
linear-gradient(rgba(233, 239, 235, .04) 1px, transparent 1px),
linear-gradient(90deg, rgba(233, 239, 235, .04) 1px, transparent 1px);
background-size: 34px 34px;
}
h1 {
font: 600 clamp(2.9rem, 7vw, 4.7rem)/.96 var(--sans);
letter-spacing: -.04em;
margin: 0;
max-width: 9ch;
}
.lede {
font-size: 1.12rem;
line-height: 1.6;
color: var(--ink-soft);
margin: 0;
max-width: 46ch;
}
@media (max-width: 720px) {
.page-head { grid-template-columns: 1fr; gap: 1rem; padding-top: .8rem; }
h1 { max-width: none; }
}
/* ---- five-step pipeline ---- */
.pipeline {
list-style: none;
margin: 1.7rem 0 0;
padding: 0;
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
border-top: 1px solid var(--rule);
}
.pipeline li {
padding: .95rem 1rem 1.1rem;
border-left: 1px solid var(--rule);
min-width: 0;
}
.pipeline li:first-child { border-left: 0; padding-left: 0; }
.pipeline .n {
display: block;
font: 600 .72rem/1 var(--mono);
letter-spacing: .08em;
color: var(--accent-deep);
margin-bottom: .6rem;
}
.pipeline strong {
display: block;
font: 600 .97rem/1.25 var(--sans);
margin-bottom: .3rem;
}
.pipeline .d { font-size: .9rem; line-height: 1.45; color: var(--ink-soft); }
@media (max-width: 900px) {
.pipeline { grid-template-columns: 1fr 1fr; }
.pipeline li:nth-child(3) { border-left: 0; padding-left: 0; }
.pipeline li:nth-child(n+3) { border-top: 1px solid var(--rule); }
}
@media (max-width: 560px) {
.pipeline { grid-template-columns: 1fr; }
.pipeline li { border-left: 0; border-top: 1px solid var(--rule); padding-left: 0; }
.pipeline li:first-child { border-top: 0; }
}
/* ---- the walkthrough ---- */
.workbench {
margin-top: 1.4rem;
padding: 1.2rem;
background: var(--panel);
color: var(--panel-ink);
border: 1px solid #08100c;
border-top: 2px solid var(--accent);
}
.workbench code { background: rgba(231, 237, 232, .1); }
.bench-head {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: baseline;
gap: .4rem 1rem;
padding-bottom: .9rem;
border-bottom: 1px solid var(--panel-edge);
font: 500 .74rem/1.4 var(--mono);
letter-spacing: .04em;
color: var(--panel-muted);
}
.bench-title { color: var(--panel-ink); }
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: .65rem 1.1rem;
padding: 1rem 0 .35rem;
}
.field {
display: flex;
align-items: center;
gap: .5rem;
font: 500 .72rem/1 var(--mono);
color: var(--panel-muted);
}
select {
font: 500 .8rem/1 var(--mono);
color: var(--panel-ink);
background: #17231d;
border: 1px solid var(--panel-edge);
border-radius: 2px;
padding: .45rem .55rem;
max-width: 100%;
}
button {
font: 500 .77rem/1 var(--mono);
color: var(--panel-ink);
background: #17231d;
border: 1px solid var(--panel-edge);
border-radius: 2px;
padding: .5rem .7rem;
cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); color: #fff; }
button:disabled { opacity: .32; cursor: not-allowed; }
button.primary {
background: var(--accent);
border-color: var(--accent);
color: #07110d;
font-weight: 600;
}
button.primary:hover:not(:disabled) { background: #9be6e4; color: #07110d; }
.button-group { display: flex; flex-wrap: wrap; gap: .35rem; }
.example-note {
margin: .2rem 0 .6rem;
font: 400 .86rem/1.5 var(--serif);
color: var(--panel-muted);
max-width: 72ch;
}
.progress-line { display: flex; align-items: center; gap: .85rem; margin: .1rem 0 1rem; }
.bar { flex: 1; height: 3px; background: var(--panel-edge); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .16s linear; }
.progress-text {
font: 500 .72rem/1 var(--mono);
color: var(--panel-muted);
white-space: nowrap;
}
.stage-grid {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
gap: 1rem;
align-items: stretch;
}
@media (max-width: 880px) { .stage-grid { grid-template-columns: 1fr; } }
.panel {
margin: 0;
min-width: 0;
display: flex;
flex-direction: column;
background: var(--panel-2);
border: 1px solid var(--panel-edge);
padding: .85rem .95rem 1rem;
}
.panel-wide { margin-top: 1rem; }
.panel-head {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: baseline;
gap: .3rem .8rem;
margin-bottom: .7rem;
}
.panel-kicker {
font: 600 .69rem/1.2 var(--mono);
letter-spacing: .06em;
color: var(--accent);
}
.panel-cap {
font: 400 .7rem/1.35 var(--mono);
color: var(--panel-muted);
text-align: right;
}
.panel-body { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.panel-foot {
margin: .6rem 0 0;
font: 400 .75rem/1.45 var(--sans);
color: var(--panel-muted);
max-width: none;
}
.diagram { display: block; width: 100%; max-width: 560px; height: auto; margin: 0 auto; }
/* frame grid */
.frame {
display: grid;
grid-template-columns: 1.5rem repeat(var(--cols), minmax(0, 1fr));
gap: 3px;
width: 100%;
max-width: var(--maxw, 100%);
margin: 0 auto;
}
.frame-corner { }
.frame-axis {
display: flex;
align-items: center;
justify-content: center;
font: 500 .64rem/1 var(--mono);
color: var(--panel-muted);
}
.frame-axis.col-axis { height: 1.1rem; }
.frame-axis.row-axis { justify-content: flex-end; padding-right: .2rem; }
.frame-axis.row-axis.active { color: var(--accent); }
.frame-cell {
aspect-ratio: 1;
display: flex;
align-items: center;
justify-content: center;
font: 600 clamp(.58rem, 2.9vw, .95rem)/1 var(--mono);
border: 1px solid rgba(231, 237, 232, .13);
background: rgba(231, 237, 232, .03);
}
.frame-cell.filled { border-color: transparent; }
.cell-value {
padding: .04em .2em;
border-radius: 2px;
background: rgba(0, 0, 0, .5);
color: #f2f7f3;
}
.frame-cell.light .cell-value { background: rgba(255, 255, 255, .85); color: #14201b; }
.frame-cell.current { box-shadow: inset 0 0 0 2px var(--accent); }
@media (prefers-reduced-motion: no-preference) {
.frame-cell.current { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe {
0%, 100% { box-shadow: inset 0 0 0 2px var(--accent); }
50% { box-shadow: inset 0 0 0 4px rgba(99, 208, 207, .45); }
}
}
@media (prefers-reduced-motion: reduce) {
.bar span { transition: none; }
}
/* ---- nearest-cube close-up (HTML, so it never clips) ---- */
@media (max-width: 380px) {
.workbench { padding: .8rem; }
.panel { padding: .7rem .65rem .8rem; }
.frame { gap: 2px; }
}
.sample-top {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: .4rem 1.2rem;
margin-bottom: .9rem;
font: 500 .73rem/1.45 var(--mono);
color: var(--panel-muted);
}
.sample-top strong { color: var(--panel-ink); font-weight: 500; }
.sample-grid {
display: grid;
grid-template-columns: minmax(0, 1fr) 16rem;
gap: 1.4rem;
align-items: start;
}
@media (max-width: 780px) { .sample-grid { grid-template-columns: 1fr; } }
.axis-row {
display: grid;
grid-template-columns: 1.3rem minmax(0, 1fr) 9.5rem;
gap: .7rem;
align-items: center;
margin-bottom: .7rem;
}
.axis-name { font: 600 .78rem/1 var(--mono); color: var(--accent); }
.ruler { position: relative; padding-top: 1.15rem; min-width: 0; }
.ticks { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; }
.tick {
font: 500 .64rem/1 var(--mono);
color: var(--panel-muted);
text-align: center;
padding: .4rem 0;
border: 1px solid rgba(231, 237, 232, .14);
border-left: 0;
background: rgba(231, 237, 232, .02);
}
.tick:first-child { border-left: 1px solid rgba(231, 237, 232, .14); }
.tick.chosen { background: rgba(99, 208, 207, .16); color: #dffbfa; box-shadow: inset 0 0 0 1px var(--accent); }
.tick.out { border-top-style: dashed; border-bottom-style: dashed; color: rgba(255, 138, 122, .55); }
.tick.chosen.out { background: rgba(255, 138, 122, .14); box-shadow: inset 0 0 0 1px var(--danger); color: #ffd7d1; }
.marker { position: absolute; top: 1.15rem; bottom: 0; width: 0; border-left: 1px dashed var(--accent); }
.marker b {
position: absolute;
top: -.1rem;
left: 0;
transform: translateX(-50%);
font: 600 .64rem/1 var(--mono);
color: var(--accent);
background: var(--panel-2);
padding: 0 .2rem;
white-space: nowrap;
}
.axis-result { font: 500 .72rem/1.4 var(--mono); text-align: right; color: var(--panel-ink); }
.axis-result .tie { color: var(--accent); }
.axis-result .off { color: var(--danger); }
.ruler-note { margin: .15rem 0 0; font: 400 .72rem/1.5 var(--sans); color: var(--panel-muted); max-width: none; }
@media (max-width: 540px) {
.axis-row { grid-template-columns: 1.2rem minmax(0, 1fr); gap: .35rem .6rem; }
.axis-result { grid-column: 2; text-align: left; margin-top: -.25rem; }
}
.readout {
border: 1px solid var(--panel-edge);
background: #101a15;
padding: .85rem .9rem;
}
.readout-label {
display: block;
margin-bottom: .35rem;
font: 600 .65rem/1 var(--mono);
letter-spacing: .06em;
color: var(--panel-muted);
}
.verdict { display: flex; align-items: center; gap: .7rem; margin-bottom: .7rem; }
.swatch {
width: 2.7rem;
height: 2.7rem;
flex: none;
border: 1px solid rgba(231, 237, 232, .25);
}
.verdict strong { font: 600 1.55rem/1 var(--mono); letter-spacing: -.02em; }
.verdict.black strong { color: var(--panel-muted); }
.readout dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .18rem .7rem; font: 400 .73rem/1.5 var(--mono); }
.readout dt { color: var(--panel-muted); }
.readout dd { margin: 0; color: var(--panel-ink); overflow-wrap: anywhere; }
.readout .why { margin: .6rem 0 0; font: 400 .78rem/1.5 var(--sans); color: var(--panel-muted); max-width: none; }
.readout .why.bad { color: #ffb2a7; }
.narration {
margin-top: 1rem;
padding: .75rem .9rem;
background: #17231d;
border-left: 2px solid var(--accent);
font: 400 .88rem/1.55 var(--serif);
color: var(--panel-ink);
min-height: 3.3em;
}
.narration b { font: 500 .88em/1 var(--mono); color: #c8f2f0; }
.fixture-check {
margin: .55rem 0 0;
font: 500 .72rem/1.45 var(--mono);
color: var(--panel-muted);
max-width: none;
}
.fixture-check.ok { color: #a9e8b0; }
.fixture-check.bad { color: var(--danger); }
/* ---- formulas ---- */
.formulas { margin-top: 1.4rem; border-top: 1px solid var(--rule); }
.formula {
display: grid;
grid-template-columns: 11rem minmax(0, 1fr) minmax(0, 17rem);
gap: .35rem 1.2rem;
align-items: baseline;
padding: .6rem 0;
border-bottom: 1px solid var(--rule);
}
.f-name { font: 600 .81rem/1.45 var(--mono); color: var(--accent-deep); overflow-wrap: anywhere; }
.f-expr { font: 400 .81rem/1.6 var(--mono); overflow-wrap: anywhere; }
.f-note { font: 400 .84rem/1.45 var(--serif); color: var(--ink-soft); }
@media (max-width: 800px) {
.formula { grid-template-columns: 1fr; gap: .1rem; }
}
/* ---- names table ---- */
.chip {
display: inline-block;
padding: .06rem .48rem;
border-radius: 999px;
color: #fff;
font: 500 .78rem/1.5 var(--mono);
white-space: nowrap;
}
.tl { background: var(--c-top-left); }
.tr { background: var(--c-top-right); }
.bl { background: var(--c-bottom-left); }
.br { background: var(--c-bottom-right); }
.table-wrap { margin-top: 1.2rem; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .87rem; }
th {
font: 600 .68rem/1 var(--mono);
letter-spacing: .04em;
text-align: left;
color: var(--ink-soft);
border-bottom: 1px solid var(--ink);
padding: .5rem .65rem;
white-space: nowrap;
}
td { border-bottom: 1px solid var(--rule); padding: .55rem .65rem; vertical-align: top; }
td:first-child { white-space: nowrap; }
td code { font-size: .8rem; }
@media (max-width: 760px) {
.table-wrap { overflow: visible; }
table, thead, tbody, tr, td { display: block; width: 100%; }
thead { display: none; }
tr { border-bottom: 1px solid var(--rule); padding: .65rem 0; }
td, td:first-child { border: 0; padding: .1rem 0; white-space: normal; }
td code { overflow-wrap: anywhere; }
td:nth-child(3)::before {
content: "CSV: ";
font: 500 .72rem/1.6 var(--mono);
color: var(--ink-soft);
}
td.empty { display: none; }
}
/* ---- gray levels ---- */
.graybar {
height: 2.2rem;
margin-top: 1.1rem;
background: linear-gradient(90deg, #000 0%, #808080 50%, #fff 100%);
border: 1px solid var(--rule);
}
.graylabels {
display: flex;
justify-content: space-between;
font: 500 .68rem/2 var(--mono);
color: var(--ink-soft);
}
.footnote { margin-top: 3.2rem; padding-top: 1rem; border-top: 1px solid var(--rule); font-size: .88rem; color: var(--ink-soft); }
</style>
</head>
<body>
<!-- Links are written relative to the Pages site root; the deploy workflow
stages this file next to index.html. -->
<header class="site-header">
<div class="wrap bar">
<img src="favicon.svg" alt="">
<a class="brand" href="index.html">plane-projection <small>demo & docs</small></a>
<nav>
<a href="index.html#demo">demo</a>
<a href="index.html#benchmarks">benchmarks</a>
<a href="algorithm.md">full spec</a>
<a class="cta" href="https://github.com/ofeq-dev/plane-projection">GitHub ↗</a>
</nav>
</div>
</header>
<main>
<header class="page-head">
<h1>From plane<br>to pixel</h1>
<p class="lede">
A flat plane cuts through a block of voxels. Every pixel of that plane asks
<em>which cube is closest?</em> and copies that cube's brightness. This page
plays the answer out one sample at a time, on the five hand-checked examples
in <a href="algorithm.md">docs/algorithm.md</a>.
</p>
</header>
<section aria-labelledby="idea-heading">
<h2 id="idea-heading">The idea, in five steps</h2>
<p>
Think of the volume as a block of small cubes, each holding one brightness
number. A plane from the CSV is a flat sheet placed inside — or running past —
that block. The renderer turns the sheet into a frame of one pixel per sample.
The whole job is the five steps below.
</p>
<ol class="pipeline">
<li><span class="n">01</span><strong>Size the frame</strong>
<span class="d">One row per voxel-length step down the legs, one column per step across the base.</span></li>
<li><span class="n">02</span><strong>Slide the rows down</strong>
<span class="d">Each row's ends sit on the two legs. No row is wider than the base, and the last row spans it exactly — triangles widen the whole way down; a rectangle keeps every row full width.</span></li>
<li><span class="n">03</span><strong>Place the pixel centres</strong>
<span class="d">Pixels sit one step apart, symmetric about the row's centre. The row stays centred as its width changes.</span></li>
<li><span class="n">04</span><strong>Find the nearest cube</strong>
<span class="d">Round the sample point to whole x, y, z indices. An exact half goes to the even index.</span></li>
<li><span class="n">05</span><strong>Copy the value</strong>
<span class="d">Map the cube's value over its storage type's full range to 0–255. A sample that misses the plane or the volume stays black.</span></li>
</ol>
</section>
<section aria-labelledby="walk-heading">
<h2 id="walk-heading">Walk it through</h2>
<div class="workbench">
<div class="bench-head">
<span class="bench-title">Interactive walkthrough</span>
<span>5 examples · ← → step pixels · ↑ ↓ step rows · space plays</span>
</div>
<div class="controls">
<label class="field" for="example">Example
<select id="example"></select>
</label>
<div class="button-group" role="group" aria-label="Step through pixels and rows">
<button id="prev-pixel" type="button" title="Back one pixel (←)">‹ previous pixel</button>
<button id="next-pixel" type="button" title="Forward one pixel (→)">next pixel ›</button>
<button id="prev-row" type="button" title="Back one row (↑)">‹ previous row</button>
<button id="next-row" type="button" title="Forward one row (↓)">next row ›</button>
</div>
<div class="button-group">
<button id="play" class="primary" type="button" title="Play or pause (space)">▶ play</button>
<button id="reset" type="button" title="Clear the frame and go back to the start">↺ reset</button>
</div>
</div>
<p class="example-note" id="example-note"></p>
<div class="progress-line">
<div class="bar" aria-hidden="true"><span id="progress-fill"></span></div>
<span class="progress-text" id="progress" aria-live="polite"></span>
</div>
<div class="stage-grid">
<figure class="panel">
<figcaption class="panel-head">
<span class="panel-kicker">01 · the plane</span>
<span class="panel-cap" id="plane-cap"></span>
</figcaption>
<div class="panel-body" id="plane-box"></div>
<p class="panel-foot">The plane is drawn flat, as if unfolded. Rows run left → right; the legs run top → bottom. On the row being sampled: the dashed verticals are the walls between cubes along the axis the row travels, each placed dot carries the cube its sample lands on, and the pixel being placed shows its original (pre-rounding) value with the cube that value rounds to.</p>
</figure>
<figure class="panel">
<figcaption class="panel-head">
<span class="panel-kicker">02 · the frame</span>
<span class="panel-cap" id="frame-cap"></span>
</figcaption>
<div class="panel-body" id="frame-box"></div>
<p class="panel-foot">One cell per pixel, filled in reading order. The number is the pixel's gray level, 0–255.</p>
</figure>
</div>
<figure class="panel panel-wide">
<figcaption class="panel-head">
<span class="panel-kicker">03 · the nearest cube</span>
<span class="panel-cap">rounding one sample point to whole indices</span>
</figcaption>
<div id="sample-box"></div>
</figure>
<p class="narration" id="narration" aria-live="polite"></p>
<p class="fixture-check" id="fixture-check"></p>
</div>
</section>
<section aria-labelledby="formulas-heading">
<h2 id="formulas-heading">The formulas, with plain names</h2>
<p>
These are the same formulas as <code>docs/algorithm.md</code>, using the names
the code in <code>Ex0.py</code> uses. Coordinates are voxel indices: no origin,
spacing, or world-space offset is applied.
</p>
<div class="formulas">
<div class="formula"><code class="f-name">leg_length</code><code class="f-expr">(dist(top_left, bottom_left) + dist(top_right, bottom_right)) / 2</code><span class="f-note">the two legs agree within EPS = 0.001</span></div>
<div class="formula"><code class="f-name">base_length</code><code class="f-expr">dist(bottom_left, bottom_right)</code><span class="f-note"></span></div>
<div class="formula"><code class="f-name">frame_height</code><code class="f-expr">max(1, round(leg_length))</code><span class="f-note">one row per voxel-length unit</span></div>
<div class="formula"><code class="f-name">frame_width</code><code class="f-expr">max(1, round(base_length))</code><span class="f-note">one column per voxel-length unit</span></div>
<div class="formula"><code class="f-name">row_fraction</code><code class="f-expr">(row_index + 1) / frame_height</code><span class="f-note">one leg step taken before each row</span></div>
<div class="formula"><code class="f-name">left_edge[row]</code><code class="f-expr">top_left + row_fraction × (bottom_left − top_left)</code><span class="f-note">slides down the left leg</span></div>
<div class="formula"><code class="f-name">right_edge[row]</code><code class="f-expr">top_right + row_fraction × (bottom_right − top_right)</code><span class="f-note">slides down the right leg</span></div>
<div class="formula"><code class="f-name">row_centre</code><code class="f-expr">(left_edge + right_edge) / 2</code><span class="f-note"></span></div>
<div class="formula"><code class="f-name">row_width</code><code class="f-expr">dist(left_edge, right_edge)</code><span class="f-note"></span></div>
<div class="formula"><code class="f-name">row_direction</code><code class="f-expr">(right_edge − left_edge) / row_width</code><span class="f-note">a one-unit step across the row</span></div>
<div class="formula"><code class="f-name">offset_from_centre</code><code class="f-expr">column_index + 0.5 − frame_width / 2</code><span class="f-note">pixel centres, symmetric about the row centre</span></div>
<div class="formula"><code class="f-name">sample_point</code><code class="f-expr">row_centre + offset_from_centre × row_direction</code><span class="f-note"></span></div>
<div class="formula"><code class="f-name">voxel_index</code><code class="f-expr">rint(sample_point)</code><span class="f-note">nearest cube; an exact half goes to the even index</span></div>
<div class="formula"><code class="f-name">inside_row</code><code class="f-expr">|offset_from_centre| ≤ row_width / 2</code><span class="f-note">plus a tiny tolerance for floating-point error</span></div>
<div class="formula"><code class="f-name">inside_volume</code><code class="f-expr">0 ≤ voxel_index < volume.shape</code><span class="f-note">a miss stays black; it is never clamped to the edge</span></div>
<div class="formula"><code class="f-name">gray_level</code><code class="f-expr">inside ? round(255 × (value − type_min) / (type_max − type_min)) : 0</code><span class="f-note">the type's full range, never the frame's own brightest value</span></div>
</div>
</section>
<section aria-labelledby="names-heading">
<h2 id="names-heading">The names used on this page</h2>
<p>
The CSV letters stay in error messages. Every computed quantity has a plain
name instead — the same one the code uses.
</p>
<div class="table-wrap">
<table>
<thead>
<tr><th>name</th><th>meaning</th><th>CSV letter(s)</th></tr>
</thead>
<tbody>
<tr><td><span class="chip tl">top_left</span> <span class="chip tr">top_right</span></td>
<td>The plane's two top corners. For a triangle they are the same point, the apex.</td>
<td><code>a1</code>, <code>a2</code> (triangle: <code>a</code>)</td></tr>
<tr><td><span class="chip bl">bottom_left</span> <span class="chip br">bottom_right</span></td>
<td>The two bottom corners. The base runs between them.</td>
<td><code>b</code>, <code>c</code></td></tr>
<tr><td><code>leg_length</code></td>
<td>Average of the two leg lengths, top corner to opposite bottom corner.</td><td class="empty">—</td></tr>
<tr><td><code>base_length</code></td><td>Distance between the two bottom corners.</td><td class="empty">—</td></tr>
<tr><td><code>frame_height</code>, <code>frame_width</code></td>
<td>The frame's row and column counts, clamped to at least 1.</td><td class="empty">—</td></tr>
<tr><td><code>row_index</code>, <code>row_fraction</code></td>
<td>Which row, and how far down the legs it sits.</td><td class="empty">—</td></tr>
<tr><td><code>left_edge</code>, <code>right_edge</code>, <code>row_centre</code>, <code>row_width</code>, <code>row_direction</code></td>
<td>The row's two ends, its midpoint, its length, and a one-unit step across it.</td><td class="empty">—</td></tr>
<tr><td><code>column_index</code>, <code>offset_from_centre</code></td>
<td>Which pixel in the row, and its signed distance from the row centre.</td><td class="empty">—</td></tr>
<tr><td><code>sample_point</code>, <code>voxel_index</code></td>
<td>The pixel's 3D sample point, and that point rounded to whole cube indices.</td><td class="empty">—</td></tr>
<tr><td><code>volume</code></td>
<td>The 3D input array <code>volume[x][y][z]</code> — the brief's <code>M</code>. Each value is an integer of one fixed bit width (numpy's <em>dtype</em>).</td><td><code>M[x][y][z]</code></td></tr>
</tbody>
</table>
</div>
</section>
<section aria-labelledby="gray-heading">
<h2 id="gray-heading">From 16-bit values to gray levels</h2>
<p>
Gray levels only run 0 to 255, so every value is mapped over its storage
type's full span — not over the picture's own brightest value. An 8-, 16- or
32-bit unsigned type maps its whole range (0..255, 0..65535, or
0..4294967295) onto 0..255. A signed type maps its minimum..maximum, so
<code>int16</code> takes −32768..32767 onto 0..255 and zero lands at
mid-gray.
</p>
<div class="graybar" aria-hidden="true"></div>
<div class="graylabels" aria-hidden="true"><span>0</span><span>128</span><span>255</span></div>
<p style="margin-top:1rem">
A dark pixel really is dark in the video. Nothing is stretched to make the
frame look brighter, and a sample that misses stays black.
</p>
</section>
<p class="footnote">
The numbers come from the hand-checked tables in <code>docs/algorithm.md</code>
and the byte-identical goldens in <code>tests/golden/</code>. Every time a walk
finishes, the page recomputes the frame and compares it to the fixture.
</p>
</main>
<footer class="site-footer">
<div class="wrap foot">
<img src="favicon.svg" alt="">
<span>plane-projection — I2SE Exercise 1</span>
<span class="spacer"></span>
<a href="index.html">demo home</a>
<a href="https://github.com/ofeq-dev/plane-projection">GitHub</a>
<a href="https://github.com/ofeq-dev/plane-projection/blob/master/LICENSE">MIT License</a>
</div>
</footer>
<script>
"use strict";
// ---------------------------------------------------------------------------
// Examples: the five hand-checked fixtures of docs/algorithm.md
// ---------------------------------------------------------------------------
const SHORT_VALUES = [-32768, 0, 32767, 100, -100];
const EXAMPLES = {
triangle: {
label: "Triangle · 2 × 4",
blurb: "A 3-point plane, two rows tall. The top row is narrow, so its outer pixel centres fall outside the plane and stay black.",
corners: { top_left: [2, 2, 0], top_right: [2, 2, 0],
bottom_left: [0, 2, 0], bottom_right: [4, 2, 0] },
shape: [6, 5, 5],
dtype: "uint8",
value: (voxel) => voxel[0],
expected: [[0, 2, 2, 0], [0, 2, 2, 4]],
},
trapezoid: {
label: "Trapezoid · 4 × 6",
blurb: "A 4-point plane. Here each row is wider than the one above as its ends slide down the two legs, until the last row spans the whole base.",
corners: { top_left: [2, 2, 0], top_right: [4, 2, 0],
bottom_left: [0, 6, 0], bottom_right: [6, 6, 0] },
shape: [8, 8, 5],
dtype: "uint8",
value: (voxel) => voxel[0],
expected: [[0, 2, 2, 4, 4, 0], [0, 2, 2, 4, 4, 0],
[0, 2, 2, 4, 4, 6], [0, 2, 2, 4, 4, 6]],
},
out_of_volume: {
label: "Past the edge · 4 × 8",
blurb: "The plane reaches past a 4 × 4 × 4 volume. A sample whose nearest cube lies outside the block stays black — it is never clamped to the edge.",
corners: { top_left: [2, 2, 2], top_right: [2, 2, 2],
bottom_left: [-2, 2, 2], bottom_right: [6, 2, 2] },
shape: [4, 4, 4],
dtype: "uint8",
value: () => 255,
expected: [[0, 0, 0, 255, 255, 0, 0, 0],
[0, 0, 255, 255, 255, 0, 0, 0],
[0, 255, 255, 255, 255, 0, 0, 0],
[0, 255, 255, 255, 255, 0, 0, 0]],
},
rounding_tie: {
label: "Rounding tie · 6 × 4",
blurb: "The plane sits at x = 2.5, so every in-volume sample is exactly halfway between cubes 2 and 3. Half-to-even picks 2, not 3.",
corners: { top_left: [2.5, 2, 0], top_right: [2.5, 2, 0],
bottom_left: [2.5, 0, 6], bottom_right: [2.5, 4, 6] },
shape: [3, 6, 7],
dtype: "uint8",
value: (voxel) => voxel[0],
expected: [[0, 0, 0, 0],
[0, 2, 2, 0],
[0, 2, 2, 0],
[0, 2, 2, 0],
[2, 2, 2, 2],
[2, 2, 2, 2]],
},
short_scaling: {
label: "Signed int16 · 5 × 5",
blurb: "An int16 volume with hand-picked extremes. Brightness uses the full −32768…32767 range, so a stored 0 becomes mid-gray 128.",
corners: { top_left: [2, 0, 0], top_right: [2, 0, 0],
bottom_left: [-0.5, 4, 0], bottom_right: [4.5, 4, 0] },
shape: [5, 5, 1],
dtype: "int16",
value: (voxel) => SHORT_VALUES[voxel[0]] ?? 0,
expected: [[0, 0, 255, 0, 0],
[0, 128, 255, 128, 0],
[0, 128, 255, 128, 0],
[0, 128, 255, 128, 127],
[0, 128, 255, 128, 127]],
},
};
const DTYPE_RANGE = {
uint8: [0, 255],
uint16: [0, 65535],
uint32: [0, 4294967295],
int8: [-128, 127],
int16: [-32768, 32767],
int32: [-2147483648, 2147483647],
};
const CORNER_COLORS = { top_left: "#c99ae8", top_right: "#f0a878",
bottom_left: "#6fd3df", bottom_right: "#b5d68c" };
const CSV_LETTER = { top_left: "a1", top_right: "a2",
bottom_left: "b", bottom_right: "c" };
// ---------------------------------------------------------------------------
// The algorithm — same names and formulas as docs/algorithm.md
// ---------------------------------------------------------------------------
// NumPy's rint: round to nearest, exact ties to the even side.
function rint(value) {
const floor = Math.floor(value);
const fraction = value - floor;
if (fraction < 0.5) return floor;
if (fraction > 0.5) return floor + 1;
return floor % 2 === 0 ? floor : floor + 1;
}
const dist3 = (p, q) => Math.hypot(p[0] - q[0], p[1] - q[1], p[2] - q[2]);
const lerp3 = (start, end, fraction) =>
[0, 1, 2].map((axis) => start[axis] + (end[axis] - start[axis]) * fraction);
const fmt = (n) => (Number.isInteger(n) ? String(n) : n.toFixed(2).replace(/\.?0+$/, ""));
// Display scaling: the storage type's full span -> 0..255, never content-stretched.
function grayLevel(example, raw) {
const [min, max] = DTYPE_RANGE[example.dtype];
return rint(((raw - min) / (max - min)) * 255);
}
function buildModel(example) {
const top_left = example.corners.top_left, top_right = example.corners.top_right;
const bottom_left = example.corners.bottom_left, bottom_right = example.corners.bottom_right;
const legLength = (dist3(top_left, bottom_left) + dist3(top_right, bottom_right)) / 2;
const baseLength = dist3(bottom_left, bottom_right);
const frameHeight = Math.max(1, rint(legLength));
const frameWidth = Math.max(1, rint(baseLength));
const rows = [];
for (let rowIndex = 0; rowIndex < frameHeight; rowIndex++) {
const rowFraction = (rowIndex + 1) / frameHeight;
const leftEdge = lerp3(top_left, bottom_left, rowFraction);
const rightEdge = lerp3(top_right, bottom_right, rowFraction);
const rowCentre = [0, 1, 2].map((axis) => (leftEdge[axis] + rightEdge[axis]) / 2);
const rowWidth = dist3(leftEdge, rightEdge);
const rowDirection = [0, 1, 2].map(
(axis) => (rightEdge[axis] - leftEdge[axis]) / (rowWidth || 1));
const pixels = [];
for (let columnIndex = 0; columnIndex < frameWidth; columnIndex++) {
const offsetFromCentre = columnIndex + 0.5 - frameWidth / 2;
const samplePoint = [0, 1, 2].map(
(axis) => rowCentre[axis] + offsetFromCentre * rowDirection[axis]);
const voxelIndex = samplePoint.map(rint);
const insideRow = Math.abs(offsetFromCentre) <= rowWidth / 2 + 1e-9;
const insideVolume = [0, 1, 2].every(
(axis) => voxelIndex[axis] >= 0 && voxelIndex[axis] < example.shape[axis]);
const inside = insideRow && insideVolume;
const rawValue = inside ? example.value(voxelIndex) : 0;
const gray = inside ? grayLevel(example, rawValue) : 0;
pixels.push({ offsetFromCentre, samplePoint, voxelIndex,
insideRow, insideVolume, inside, rawValue, gray });
}
rows.push({ rowIndex, rowFraction, leftEdge, rightEdge, rowCentre,
rowDirection, rowWidth, pixels });
}
return { legLength, baseLength, frameHeight, frameWidth, rows };
}
function renderFrame(model) {
return model.rows.map((row) => row.pixels.map((pixel) => pixel.gray));
}
function allSteps(model) {
const steps = [];
model.rows.forEach((row, rowIndex) =>
row.pixels.forEach((pixel, columnIndex) =>
steps.push({ rowIndex, columnIndex, pixel })));
return steps;
}
function currentStep(state) {
return state.steps[state.order] ?? null;
}
// Whether a coordinate landed on an exact .5 boundary (for the tie note).
function isTie(value) {
return Math.abs(value - Math.floor(value) - 0.5) < 1e-9;
}
// ---------------------------------------------------------------------------
// 01 · the plane, unfolded. Pure SVG string; viewBox 600 x 420.
// ---------------------------------------------------------------------------
function planeGeometry(example, model) {
const width = 480, height = 400;
const padL = 54, padR = 54, padT = 88, padB = 70;
const topWidth = dist3(example.corners.top_left, example.corners.top_right);
const scale = Math.min(
(width - padL - padR) / Math.max(model.baseLength, 1e-9),
(height - padT - padB) / Math.max(model.legLength, 1e-9));
const cx = width / 2;
return {
width, height, padT, scale, cx, topWidth,
toXY: (u, v) => [cx + u * scale, padT + v * scale],
};
}
function drawPlane(example, model, state) {
const g = planeGeometry(example, model);
const { toXY, cx, padT } = g;
const scale = g.scale;
const leg = model.legLength;
const topHalf = g.topWidth / 2, baseHalf = model.baseLength / 2;
const current = currentStep(state);
const topY = padT;
const mono = "IBM Plex Mono, ui-monospace, monospace";
const at = (u, v) => toXY(u, v).map((n) => n.toFixed(1));
let s = "";
// Rows: already walked, the one being sampled, and still ahead.
model.rows.forEach((row, rowIndex) => {
const f = row.rowFraction;
const v = f * leg;
const leftU = -topHalf + f * (-baseHalf + topHalf);
const rightU = topHalf + f * (baseHalf - topHalf);
const [x1, y1] = at(leftU, v), [x2, y2] = at(rightU, v);
const isCurrent = current !== null && rowIndex === current.rowIndex;
const walked = current === null || rowIndex < current.rowIndex;
const color = isCurrent ? "#63d0cf"
: walked ? "rgba(99, 208, 207, .42)" : "rgba(231, 237, 232, .15)";
s += `<line x1="${x1}" x2="${x2}" y1="${y1}" y2="${y2}"
stroke="${color}" stroke-width="${isCurrent ? 2.4 : walked ? 1.3 : 1}"/>`;
});
// Outline: top edge, right leg, base, left leg.
const outline = [[-topHalf, 0], [topHalf, 0], [baseHalf, leg], [-baseHalf, leg]];
s += `<polygon points="${outline.map(([u, v]) => at(u, v).join(",")).join(" ")}"
fill="rgba(231, 237, 232, .045)" stroke="rgba(231, 237, 232, .5)" stroke-width="1.3"/>`;
// Pixel-centre positions along the current row, with the sampled ones marked.
if (current) {
const row = model.rows[current.rowIndex];
const v = row.rowFraction * leg;
// This unfolded view is symmetric about the canvas centre, so the row centre is 0.
// Cube walls of the axis the row travels along, in a band around the row, so the
// "which cube is closest?" step is visible right here in the plane view.
const absDir = row.rowDirection.map((d) => Math.abs(d));
const travelAxis = absDir.indexOf(Math.max(...absDir));
const travelDir = row.rowDirection[travelAxis];
const travelCentre = row.rowCentre[travelAxis];
const axisChar = "xyz"[travelAxis];
if (Math.abs(travelDir) > 1e-9) {
const rowY = toXY(0, v)[1];
const bandHalf = Math.min(Math.max(scale * 0.55, 10), 22);
const uHalf = row.rowWidth / 2;
const lo = Math.min(travelCentre - uHalf * travelDir, travelCentre + uHalf * travelDir);
const hi = Math.max(travelCentre - uHalf * travelDir, travelCentre + uHalf * travelDir);
for (let k = Math.ceil(lo - 0.5); k <= Math.floor(hi + 0.5); k++) {
if (k < -1 || k >= example.shape[travelAxis]) continue;
const wallU = (k + 0.5 - travelCentre) / travelDir;
const [wx] = toXY(wallU, v);
s += `<line x1="${wx.toFixed(1)}" x2="${wx.toFixed(1)}" y1="${(rowY - bandHalf).toFixed(1)}"
y2="${(rowY + bandHalf).toFixed(1)}" stroke="rgba(231, 237, 232, .3)"
stroke-width="1" stroke-dasharray="2 3"/>`;
s += `<text x="${wx.toFixed(1)}" y="${(rowY - bandHalf + 10).toFixed(1)}" text-anchor="middle"
fill="rgba(149, 166, 156, .6)" font-family="${mono}"
font-size="9">${k}|${k + 1}</text>`;
}
}
row.pixels.forEach((pixel, columnIndex) => {
const u = pixel.offsetFromCentre;
const [x, y] = at(u, v);
const sampled = columnIndex <= current.columnIndex;
const isCurrent = columnIndex === current.columnIndex;
if (!sampled) {
s += `<circle cx="${x}" cy="${y}" r="1.3" fill="rgba(231, 237, 232, .18)"/>`;
return;
}
if (isCurrent) {
if (!pixel.insideRow) {
const f = row.rowFraction;
const leftU = -topHalf + f * (-baseHalf + topHalf);
const rightU = topHalf + f * (baseHalf - topHalf);
const endU = pixel.offsetFromCentre < 0 ? leftU : rightU;
const [endX, endY] = at(endU, v);
s += `<line x1="${x}" y1="${y}" x2="${endX}" y2="${endY}"
stroke="rgba(255, 138, 122, .75)" stroke-width="1.2" stroke-dasharray="2 3"/>`;
}
s += `<circle cx="${x}" cy="${y}" r="5.6" fill="${pixel.inside ? "#63d0cf" : "#ff8a7a"}"
stroke="#101a15" stroke-width="1.6"/>`;
// Full label on the pixel being placed: its original (pre-rounding)
// value on the row's travel axis, and the cube that value lands on.
if (pixel.insideRow) {
const pre = pixel.samplePoint[travelAxis];
const post = pixel.voxelIndex[travelAxis];
let label = `${axisChar} ${fmt(pre)} → ${post}`;
if (isTie(pre)) label += ` · tie → even`;
s += `<text x="${x}" y="${(Number(y) + 17).toFixed(1)}" text-anchor="middle"
fill="${pixel.inside ? "#63d0cf" : "#ff8a7a"}" font-family="${mono}"
font-size="10.5">${label}</text>`;
const otherTie = [0, 1, 2].find(
(axis) => axis !== travelAxis && isTie(pixel.samplePoint[axis]));
if (otherTie !== undefined && pixel.inside) {
const char2 = "xyz"[otherTie];
s += `<text x="${x}" y="${(Number(y) + 29).toFixed(1)}" text-anchor="middle"