forked from shaunlebron/IsometricBlocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.htm
More file actions
604 lines (525 loc) · 21.9 KB
/
index.htm
File metadata and controls
604 lines (525 loc) · 21.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
<!doctype html>
<html>
<head>
<meta charset="utf8">
<style>
/*------------------------------------------------------------------------------
* Open Sans
*----------------------------------------------------------------------------*/
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 300;
src: url('../fonts/opensans/OpenSans-Light.eot');
src: local('Open Sans Light'), local('OpenSans-Light'),
url('../fonts/opensans/OpenSans-Light.eot') format('embedded-opentype'),
url('../fonts/opensans/OpenSans-Light.woff') format('woff');
}
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src: url('../fonts/opensans/OpenSans.eot');
src: local('Open Sans'), local('OpenSans'),
url('../fonts/opensans/OpenSans.eot') format('embedded-opentype'),
url('../fonts/opensans/OpenSans.woff') format('woff');
}
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: bold;
src: url('../fonts/opensans/OpenSans-Bold.eot');
src: local('Open Sans Bold'), local('OpenSans-Bold'),
url('../fonts/opensans/OpenSans-Bold.eot') format('embedded-opentype'),
url('../fonts/opensans/OpenSans-Bold.woff') format('woff');
}
@font-face {
font-family: 'Open Sans';
font-style: italic;
font-weight: 300;
src: local('Open Sans Light Italic'), local('OpenSansLight-Italic'),
url('../fonts/opensans/OpenSansLight-Italic.eot') format('embedded-opentype'),
url('../fonts/opensans/OpenSansLight-Italic.woff') format('woff');
}
@font-face {
font-family: 'Open Sans';
font-style: italic;
font-weight: 400;
src: local('Open Sans Italic'), local('OpenSans-Italic'),
url('../fonts/opensans/OpenSans-Italic.eot') format('embedded-opentype'),
url('../fonts/opensans/OpenSans-Italic.woff') format('woff');
}
@font-face {
font-family: 'Open Sans';
font-style: italic;
font-weight: bold;
src: local('Open Sans Bold Italic'), local('OpenSans-BoldItalic'),
url('../fonts/opensans/OpenSans-BoldItalic.eot') format('embedded-opentype'),
url('../fonts/opensans/OpenSans-BoldItalic.woff') format('woff');
}
hr {
margin-top:3em;
margin-bottom:3em;
}
body {
width: 800px;
margin-left:auto;
margin-right:auto;
font-family: 'Open Sans';
font-size: 1.2em;
}
canvas {
background-color: #f5f5f5;
margin-right: 5px;
text-align: center;
border: 1px solid #d7d7d7;
}
#abstract {
font-style: italic;
}
figure {
margin: 2em 2em;
}
figcaption {
font-style: italic;
color: #555;
}
code.block {
white-space: pre;
display:block;
margin-top:3em;
margin-bottom:3em;
margin-left: auto;
margin-right: auto;
width: 650px;
padding: 1.5em;
background: #f5f5f5;
}
h1 {
font-size: 32px;
}
h1, h2, h3, h4 {
margin-top: 3em;
margin-bottom: -1em;
color: #333;
font-weight: 600;
}
p {
margin: 3em 0;
color: #555;
line-height: 1.6em;
}
figcaption {
opacity: 0.6;
}
p.alert{
border-radius: 5px;
box-shadow: 0px 0px 2px #000;
background-color: #ef2929;
color: white;
padding: 1em;
}
/* from vim's TOhtml command for syntax highlighting code */
.lnr { color: #ff0000; }
.Constant { color: #ef2929; }
.Statement { color: #3465a4; }
.Comment { color: #4e9a06; }
.Identifier { color: #3465a4; }
</style>
<script src='src/main.js'></script>
<script src='src/colors.js'></script>
<script src='src/block.js'></script>
<script src='src/vector.js'></script>
<script src='src/camera.js'></script>
<script src='src/painter.js'></script>
<script src='src/sortBlocks.js'></script>
</head>
<body>
<a href="https://github.com/shaunew/IsometricBlocks"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a>
<h1>Drawing isometric boxes in the correct order</h1>
<p>
In an <a href="http://en.wikipedia.org/wiki/Isometric_projection">isometric</a>
display, it can be tricky to draw boxes of various sizes in the correct order
to keep them appropriately in front of or behind one another. The figure below
shows an example. The blue box should be drawn first, then green, then red.
</p>
<figure>
<canvas id='figure1a' width=350 height=200></canvas>
<canvas id='figure1b' width=350 height=200></canvas>
<figcaption>
Figure 1: The boxes on the left are <u>not</u> drawn in the correct order, whereas the
boxes on the right are drawn correctly.
</figcaption>
<script>
var blocks = [
new IsoBlock.Block({x:1,y:3,z:0},{x:2,y:2,z:2.5}, IsoBlock.colors.green),
new IsoBlock.Block({x:2,y:2,z:0},{x:1,y:1,z:1.5}, IsoBlock.colors.red),
new IsoBlock.Block({x:3,y:1,z:0},{x:1,y:4,z:1}, IsoBlock.colors.blue),
];
IsoBlock.makeFigure({ canvas:'figure1a', blocks: blocks, sortBlocks: false, });
IsoBlock.makeFigure({ canvas:'figure1b', blocks: blocks, });
</script>
</figure>
<p>
We will explore a simple solution for determining the correct order to draw a
given set of boxes. But first, we must define what we mean by <em>boxes</em>.
</p>
<h3>What do we mean by <em>boxes</em>?</h3>
<p>
We define boxes as <em>axis-aligned</em> and <em>non-intersecting</em>
rectangular prisms. Take a look at the above Figure 1 again. Each box is
parallel to the <em>x</em>, <em>y</em>, and <em>z</em> axis (i.e.
axis-aligned). Also, note that the boxes are next to each other but do not
intersect.
</p>
<h3>Determine if boxes overlap on screen.</h3>
<p>
First of all, if two boxes do not overlap on the screen, then we do not have to
worry about which one is drawn first. This is the first test we must perform,
which we explore in this section.
</p>
<figure>
<canvas id='figure2a' width=350 height=200></canvas>
<canvas id='figure2b' width=350 height=200></canvas>
<figcaption>
Figure 2: No overlap on the left; overlap on the right. (Note: we are talking
about overlap on screen, not intersection in space.)
</figcaption>
<script>
var rightBlock = new IsoBlock.Block({x:4,y:1,z:0},{x:2,y:2,z:2}, IsoBlock.colors.blue);
var leftBlock = new IsoBlock.Block({x:2,y:4,z:0},{x:2.25,y:2,z:1}, IsoBlock.colors.red);
var rightBlockOverlap = new IsoBlock.Block({x:3,y:2,z:0},{x:2,y:2,z:2}, IsoBlock.colors.blue);
var leftBlockOverlap = new IsoBlock.Block({x:2,y:4,z:0},{x:2.25,y:2,z:1}, IsoBlock.colors.green);
var scale = function(w,h) { return h/9;};
IsoBlock.makeFigure({ canvas:'figure2a',
blocks: [ leftBlock, rightBlock ],
scale: scale,
});
IsoBlock.makeFigure({ canvas:'figure2b',
blocks: [ leftBlockOverlap, rightBlockOverlap ],
scale: scale,
});
</script>
</figure>
<p>
The silhouettes of the 3D boxes become 2D hexagons in the isometric view, as seen below. We use the
outline of these silhouettes to test for overlap.
</p>
<figure>
<canvas id='figure3a' width=350 height=200></canvas>
<canvas id='figure3b' width=350 height=200></canvas>
<figcaption>
Figure 3: The box silhouettes in an isometric view are simple hexagons. Note
that their sides are always parallel to the vertical and two diagonal axes.
</figcaption>
<script>
IsoBlock.makeFigure({ canvas:'figure3a',
blocks: [ leftBlock, rightBlock ],
scale: scale,
silhouette: true,
});
IsoBlock.makeFigure({ canvas:'figure3b',
blocks: [ leftBlockOverlap, rightBlockOverlap ],
scale: scale,
silhouette: true,
});
</script>
</figure>
<p>
We take advantage of the fact that the hexagon sides are always parallel to
some axis. This allows us to easily determine if the hexagons overlap by
checking for intersection of their regions on each axis. We add an <em>h</em>
(horizontal) axis to help.
</p>
<figure>
<canvas id='figure4a' width=350 height=200></canvas>
<canvas id='figure4b' width=350 height=200></canvas>
<figcaption>
The red and blue boxes do not overlap on the h axis, therefore they do not overlap.
The green and blue boxes do overlap since their region on every axis overlap.
</figcaption>
<script>
IsoBlock.makeFigure({ canvas:'figure4a',
blocks: [ leftBlock, rightBlock ],
drawAxis: true,
silhouette: true,
scale: scale,
});
IsoBlock.makeFigure({ canvas:'figure4b',
blocks: [ leftBlockOverlap, rightBlockOverlap ],
drawAxis: true,
silhouette: true,
scale: scale,
});
</script>
</figure>
<p>
Now that we have outlined our concept for <em>determining if two boxes overlap
on the screen</em>, we will fill in the details necessary for implementing it.
</p>
<p>
The act of flattening the 3D box into a 2D hexagon involves getting rid of the
Z coordinate. Notice that increasing a point's Z coordinate by 1 is the same
as incrementing both X and Y coordinates by 1. Thus, we can add Z to both X
and Y and drop Z completely. Shown below is the source code for a function
that performs this conversion.
</p>
<code class='block'><span class="Comment">// Convert a 3D space position to a 2D isometric position.</span>
<span class="Identifier">function</span> spaceToIso(spacePos) <span class="Identifier">{</span>
<span class="Comment">// New XY position simply adds Z to X and Y.</span>
<span class="Identifier">var</span> isoX = spacePos.x + spacePos.z;
<span class="Identifier">var</span> isoY = spacePos.y + spacePos.z;
<span class="Statement">return</span> <span class="Identifier">{</span>
x: isoX,
y: isoY,
<span class="Comment">// Compute horizontal distance from origin.</span>
h: (isoX - isoY) * Math.cos(Math.PI/6),
<span class="Comment">// Compute vertical distance from origin.</span>
v: (isoX + isoY) / 2;
<span class="Identifier">}</span>;
<span class="Identifier">}</span></code>
<p>
And finally, after determining the bounds of each hexagon, we can determine if
they overlap by using the source code below.
</p>
<code class='block'><span class="Identifier">function</span> doHexagonsOverlap(hex1, hex2) <span class="Identifier">{</span>
<span class="Comment">// Hexagons overlap if and only if all axis regions overlap.</span>
<span class="Statement">return</span> (
<span class="Comment">// test if x regions intersect.</span>
!(hex1.xmin >= hex2.xmax || hex2.xmin >= hex1.xmax) &&
<span class="Comment">// test if y regions intersect.</span>
!(hex1.ymin >= hex2.ymax || hex2.ymin >= hex1.ymax) &&
<span class="Comment">// test if h regions intersect.</span>
!(hex1.hmin >= hex2.hmax || hex2.hmin >= hex1.hmax));
<span class="Identifier">}</span></code>
<p>
Now that we have determined if two boxes overlap on the screen, we can begin exploring how to determine which box is in front of the other.
</p>
<h3>Determine which box is in front.</h3>
<p>
Recall that our boxes do not intersect each other. we can visualize their separation
as a thin plane between them (see Figure 5 below). After identifying this
plane, we can determine which box is in front by selecting the one on the
correct side of this plane.
</p>
<figure>
<canvas id='figure5a' width=230 height=200></canvas>
<canvas id='figure5b' width=230 height=200></canvas>
<canvas id='figure5c' width=230 height=200></canvas>
<figcaption>
Figure 5: A pair of blocks can be separated in one of three ways shown here.
The dark glass illustrates this separation.
</figcaption>
<script>
var refBlock = new IsoBlock.Block({x:3,y:2,z:0},{x:2,y:2,z:2}, IsoBlock.colors.blue);
var leftBlock = new IsoBlock.Block({x:2,y:4,z:0},{x:2.25,y:2,z:1}, IsoBlock.colors.red);
var topBlock = new IsoBlock.Block({x:4,y:2,z:2},{x:1.25,y:2,z:1}, IsoBlock.colors.orange);
var frontBlock = new IsoBlock.Block({x:1,y:1,z:0},{x:2,y:2,z:1}, IsoBlock.colors.green);
IsoBlock.makeFigure({ canvas:'figure5a', drawPlane: true,
blocks: [ refBlock, leftBlock ],
});
IsoBlock.makeFigure({ canvas:'figure5b', drawPlane: true,
blocks: [ refBlock, topBlock ],
});
IsoBlock.makeFigure({ canvas:'figure5c', drawPlane: true,
blocks: [ refBlock, frontBlock ],
});
</script>
</figure>
<p>
We can find this plane of separation by looking at each axis individually. In
particular, we look for an axis which has non-intersecting box ranges (see
Figure 6 below).
</p>
<figure>
<canvas id='figure6a' width=350 height=200></canvas>
<canvas id='figure6b' width=350 height=200></canvas>
<figcaption>
Figure 6: On the left, the blocks are separated on the y-axis. On the right,
the blocks are separated on the x-axis. (The z-axis is omitted for simplicity.)
</figcaption>
<script>
IsoBlock.makeFigure({ canvas:'figure6a',
blocks: [ refBlock, leftBlock ],
drawAxis: true,
});
IsoBlock.makeFigure({ canvas:'figure6b',
blocks: [ refBlock, frontBlock ],
drawAxis: true,
});
</script>
</figure>
<p>
In Figure 6 above, we have chosen a coordinate system which make lesser values
of <em>x</em> and <em>y</em> to be closer to the camera. Though not shown, the
<em>z</em> axis is positive in the up direction, so a greater value makes it
closer to the camera.
</p>
<p>
The following is a javascript function for determining if the first block is in
front of the second:
</p>
<code class='block'><span class="Identifier">function</span> isBoxInFront(box1, box2) <span class="Identifier">{</span>
<span class="Comment">// test for intersection x-axis</span>
<span class="Comment">// (lower x value is in front)</span>
<span class="Statement">if</span> (box1.xmin >= box2.xmax) <span class="Identifier">{</span> <span class="Statement">return</span> <span class="Constant">false</span>; <span class="Identifier">}</span>
<span class="Statement">else</span> <span class="Statement">if</span> (box2.xmin >= box1.xmax) <span class="Identifier">{</span> <span class="Statement">return</span> <span class="Constant">true</span>; <span class="Identifier">}</span>
<span class="Comment">// test for intersection y-axis</span>
<span class="Comment">// (lower y value is in front)</span>
<span class="Statement">if</span> (box1.ymin >= box2.ymax) <span class="Identifier">{</span> <span class="Statement">return</span> <span class="Constant">false</span>; <span class="Identifier">}</span>
<span class="Statement">else</span> <span class="Statement">if</span> (box2.ymin >= box1.ymax) <span class="Identifier">{</span> <span class="Statement">return</span> <span class="Constant">true</span>; <span class="Identifier">}</span>
<span class="Comment">// test for intersection z-axis</span>
<span class="Comment">// (higher z value is in front)</span>
<span class="Statement">if</span> (box1.zmin >= box2.zmax) <span class="Identifier">{</span> <span class="Statement">return</span> <span class="Constant">true</span>; <span class="Identifier">}</span>
<span class="Statement">else</span> <span class="Statement">if</span> (box2.zmin >= box1.zmax) <span class="Identifier">{</span> <span class="Statement">return</span> <span class="Constant">false</span>; <span class="Identifier">}</span>
<span class="Identifier">}</span></code>
<h3>Draw boxes in the correct order.</h3>
<p>
In general, <u>a box should not be drawn until all the ones behind it are
drawn</u>. Thus, we begin by drawing the boxes that have nothing behind them.
Then, we can draw the boxes that are only in front of those that are already
drawn. This process continues until all boxes are drawn. (See Figure 4 below
for an example.)
</p>
<figure>
<canvas id='figure7' width=650 height=200></canvas>
<figcaption>
Figure 4: (1) Nothing is behind blue, so draw it first. (2) Draw green next
since blue was the only one behind it and is already drawn. (3) Then draw red,
since both blocks that were behind it have been drawn.
</figcaption>
<script>
var blocks = [
new IsoBlock.Block({x:1,y:3,z:0},{x:2,y:2,z:2.5}, IsoBlock.colors.green),
new IsoBlock.Block({x:2,y:2,z:0},{x:1,y:1,z:1.5}, IsoBlock.colors.red),
new IsoBlock.Block({x:3,y:1,z:0},{x:1,y:4,z:1}, IsoBlock.colors.blue),
];
IsoBlock.makeFigure({ canvas:'figure7', blocks: blocks, scale: function(w,h) { return h/7; }});
</script>
</figure>
<p>
To implement this algorithm, each box must know exactly which boxes are behind
it. We have already determined how to do this in the last section. A search
must be implemented so that each box has a list of boxes behind it.
</p>
<p>
You are now armed with everything you need to know to render isometric boxes in
the correct order.
</p>
<h3>A conundrum</h3>
<p>
It is possible to have a situation seen in the figure below. The aforementioned drawing
methods dictate that we first draw the box with nothing behind it, but this example illustrates
a case where this cannot be done.
</p>
<figure>
<canvas id='figure8' width=650 height=200></canvas>
<figcaption>
Here are three boxes intertwined in a way such that one is always behind
another. This prevents us from drawing a first box.
</figcaption>
<script>
var blocks = [
new IsoBlock.Block({x:1,y:1,z:0},{x:2,y:1,z:1}, IsoBlock.colors.purple),
new IsoBlock.Block({x:2,y:1,z:1},{x:1,y:2,z:1}, IsoBlock.colors.red),
new IsoBlock.Block({x:1,y:2,z:0},{x:1,y:1,z:1}, IsoBlock.colors.orange),
new IsoBlock.Block({x:1,y:2,z:1},{x:1,y:1,z:1}, IsoBlock.colors.orange),
];
IsoBlock.makeFigure({ canvas:'figure8', blocks: blocks, scale: function(w,h) { return h/6;} });
</script>
</figure>
<p>
The figure above cheats by segmenting the orange box into two.
This is one method of breaking this type of cycle.
</p>
<p>
There are formal methods used for detecting
such cycles mentioned in the appendix. After detection of a cycle, the blocks in that cycle
could be drawn with special clipping regions to respect front boxes or to segment a block or blocks
that will break the cycle. These are solutions that I will be exploring and updating this article as
my experiments progress.
</p>
<hr>
<h2>Appendix</h2>
<h4>A formal description of the solution</h4>
<p>
This is a special case of the <a href="https://en.wikipedia.org/wiki/Painter%27s_algorithm">Painter's Algorithm</a>,
which handles occlusion by drawing back-to-front.
</p>
<p>
For those who are interested, our method for determining if hexagons and boxes
are overlapping is a result of the <a href="http://en.wikipedia.org/wiki/Hyperplane_separation_theorem">hyperplane separation theorem</a>.
</p>
<p>
Also, the way in which we determined the drawing order of the boxes is known in graph theory as a <a
href="http://en.wikipedia.org/wiki/Topological_sorting">topological sort</a>,
which is essentially a depth-first search of a directed graph.
</p>
<p>
You can build a directed graph of the <em>boxes</em>, with directed edges to
the boxes that are behind it. Topologically sorting this graph will produce an
ordered list of boxes that can be drawn in that exact order.
</p>
<p>
Mathematicians will recognize this directed graph as a <a
href="http://en.wikipedia.org/wiki/Partially_ordered_set">partially ordered
set</a>.
</p>
<p>
Finally, to prevent the aforementioned cycle conundrum, we can use <a href="">Tarjan's
strongly connection components</a> algorithm. After computing these cycles,
one could either split a block to prevent a cycle, or to use a clipping region
to prevent drawing over any blocks that are supposed to be in front of it.
</p>
<h4>Alternative Solutions</h4>
<p>
You may be able to just use <a href="https://en.wikipedia.org/wiki/Z-buffering">Z-buffering</a>,
though drawing order is still important for transparent sprites. Also, if all
bounding boxes are unit cubes, sorting is much simpler.
</p>
<h4>Full example of working code</h4>
<p>
All the diagrams above were created using a simple isometric box renderer
written in Javascript, which applies all the techniques described in this
article. You can study the fully annotated source code on <a
href="https://github.com/shaunew/IsometricBlocks">IsometricBlocks project on
GitHub</a>.
</p>
<h4>Real game examples</h4>
<p>
<ul>
<li><a href="http://andrewrussell.net/2016/06/how-2-5d-sorting-works-in-river-city-ransom-underground/">How 2.5D Sorting works in River City Ransom: Underground</a> - allowing bounding boxes to intersect by specifying heightmaps within them (<a href="https://news.ycombinator.com/item?id=12313271">summary</a>)</li>
<li><a href="http://bannalia.blogspot.co.uk/2008/02/filmation-math.html">Filmation engine on the ZX Spectrum</a></li>
</ul>
</p>
<h4>Thanks</h4>
<p>
Thanks to Ted Suzman at <a href="http://playbuildy.com/">buildy</a> for
introducing this problem and solution to me. And thanks to adamhayek for <a
href="http://www.reddit.com/r/gamedev/comments/18222r/how_to_determine_the_draw_order_for_an_isometric/c8ayzby">further
insight</a> on a general solution. And thanks to <a href="http://www.reddit.com/r/gamedev/comments/18bg95/tutorial_how_to_render_isometric_blocks_correctly/c8dfx51">Slime0 at reddit</a> for pointing out errors in this article by illustrating the cycle example shown in this article, and for illustrating why we cannot deduce relative drawing order between two non-overlapping boxes.
Thanks to <a href="https://lobste.rs/s/bengjo/drawing_isometric_boxes_correct_order/comments/rzgvnc#c_rzgvnc">Mark Nelson</a> for extra context on painter's algorithm and z-buffering.
</p>
<hr>
<figure>
<canvas id='figure5' width=700 height=200></canvas>
<script>
var blocks = [
new IsoBlock.Block({x:1,y:3,z:0},{x:2,y:2,z:2.5}, IsoBlock.colors.green),
new IsoBlock.Block({x:2,y:2,z:0},{x:1,y:1,z:1.5}, IsoBlock.colors.red),
new IsoBlock.Block({x:3,y:1,z:0},{x:1,y:4,z:1}, IsoBlock.colors.blue),
new IsoBlock.Block({x:0.5,y:5,z:0},{x:2,y:1.5,z:1}, IsoBlock.colors.orange),
new IsoBlock.Block({x:3,y:3,z:1},{x:1,y:1,z:2.25}, IsoBlock.colors.black),
new IsoBlock.Block({x:2,y:7,z:0},{x:1,y:1,z:1}, IsoBlock.colors.white),
new IsoBlock.Block({x:5,y:1.5,z:0},{x:2,y:2,z:1.5}, IsoBlock.colors.purple),
];
IsoBlock.makeFigure({
canvas:'figure5',
blocks: blocks,
drawAxis:true,
axisLen: 12,
});
</script>
</figure>
</body>
</html>