-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgeometry.html
More file actions
1826 lines (1588 loc) · 83.6 KB
/
geometry.html
File metadata and controls
1826 lines (1588 loc) · 83.6 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.0">
<title>Geometry - Math from Zero to CS - Better Dev</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=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="topbar">
<button class="sidebar-toggle" aria-label="Open navigation" aria-expanded="false">
<span class="hamburger-icon"></span>
</button>
<a href="index.html" class="logo">Better Dev</a>
</header>
<div class="sidebar-backdrop" aria-hidden="true"></div>
<aside class="sidebar" aria-label="Site navigation">
<div class="sidebar-header">
<span class="sidebar-title">Navigation</span>
<button class="sidebar-close" aria-label="Close navigation">×</button>
</div>
<div class="sidebar-search">
<input type="text" class="sidebar-search-input" placeholder="Search topics..." aria-label="Search topics">
<div class="sidebar-search-results"></div>
</div>
<nav class="sidebar-nav">
<div class="sidebar-group">
<a href="index.html">Home</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">Mathematics</div>
<a href="pre-algebra.html">Pre-Algebra</a>
<a href="algebra.html">Algebra</a>
<a href="sequences-series.html">Sequences & Series</a>
<a href="geometry.html">Geometry</a>
<a href="calculus.html">Calculus</a>
<a href="discrete-math.html">Discrete Math</a>
<a href="linear-algebra.html">Linear Algebra</a>
<a href="probability.html">Probability & Statistics</a>
<a href="binary-systems.html">Binary & Number Systems</a>
<a href="number-theory.html">Number Theory for CP</a>
<a href="computational-geometry.html">Computational Geometry</a>
<a href="game-theory.html">Game Theory</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">Data Structures & Algorithms</div>
<a href="dsa-foundations.html">DSA Foundations</a>
<a href="arrays.html">Arrays & Strings</a>
<a href="stacks-queues.html">Stacks & Queues</a>
<a href="hashmaps.html">Hash Maps & Sets</a>
<a href="linked-lists.html">Linked Lists</a>
<a href="trees.html">Trees & BST</a>
<a href="graphs.html">Graphs</a>
<a href="sorting.html">Sorting & Searching</a>
<a href="patterns.html">LeetCode Patterns</a>
<a href="dp.html">Dynamic Programming</a>
<a href="advanced.html">Advanced Topics</a>
<a href="string-algorithms.html">String Algorithms</a>
<a href="advanced-graphs.html">Advanced Graphs</a>
<a href="advanced-dp.html">Advanced DP</a>
<a href="advanced-ds.html">Advanced Data Structures</a>
<a href="leetcode-650.html">The 650 Problems</a>
<a href="competitive-programming.html">CP Roadmap</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">Languages & Systems</div>
<a href="cpp.html">C++</a>
<a href="golang.html">Go</a>
<a href="javascript.html">JavaScript Deep Dive</a>
<a href="typescript.html">TypeScript</a>
<a href="nodejs.html">Node.js Internals</a>
<a href="os.html">Operating Systems</a>
<a href="linux.html">Linux</a>
<a href="git.html">Git</a>
<a href="backend.html">Backend</a>
<a href="system-design.html">System Design</a>
<a href="networking.html">Networking</a>
<a href="cloud.html">Cloud & Infrastructure</a>
<a href="docker.html">Docker & Compose</a>
<a href="kubernetes.html">Kubernetes</a>
<a href="message-queues.html">Queues & Pub/Sub</a>
<a href="selfhosting.html">VPS & Self-Hosting</a>
<a href="databases.html">PostgreSQL & MySQL</a>
<a href="stripe.html">Stripe & Payments</a>
<a href="distributed-systems.html">Distributed Systems</a>
<a href="backend-engineering.html">Backend Engineering</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">JS/TS Ecosystem</div>
<a href="js-tooling.html">Tooling & Bundlers</a>
<a href="js-testing.html">Testing</a>
<a href="ts-projects.html">Building with TS</a>
</div>
<div class="sidebar-group">
<div class="sidebar-group-label">More</div>
<a href="seans-brain.html">Sean's Brain</a>
</div>
</nav>
</aside>
<!-- Page Header -->
<div class="container">
<div class="page-header">
<div class="breadcrumb"><a href="index.html">Home</a> » Geometry</div>
<h1>Geometry</h1>
<p>Shapes, angles, area, volume, trigonometry, and coordinate geometry -- the math that gives structure to the visual world and powers computer graphics, game engines, and spatial computing.</p>
<div class="tip-box" style="margin-top: 1rem;">
<div class="label">Why Geometry Matters for CS -- Every Pixel is Math</div>
<p>Geometry isn't just about shapes on paper. <strong>Everything visual on a computer is geometry</strong>. Here's what each topic on this page lets you build:</p>
<ul>
<li><strong>Shapes & angles</strong> → Collision detection in games ("did the bullet hit the wall?"), UI layout calculations, bounding boxes for click detection</li>
<li><strong>Area & perimeter</strong> → Computational geometry algorithms, determining if a point is inside a polygon (used in maps, GIS, game zones)</li>
<li><strong>Volume & surface area</strong> → 3D rendering, physics simulations, voxel-based games like Minecraft</li>
<li><strong>Pythagorean theorem</strong> → Distance calculations between any two points -- used in pathfinding (A* algorithm), nearest-neighbor search, GPS, and every 2D/3D game ever made</li>
<li><strong>Trigonometry</strong> → Rotations (spinning a character, rotating an image), wave animations (CSS/canvas), physics engines (projectile motion, pendulums), audio signal processing</li>
<li><strong>Coordinate geometry</strong> → Every pixel on your screen has (x, y) coordinates. CSS positioning, SVG graphics, canvas drawing, game object positions -- all coordinate geometry</li>
<li><strong>Transformations</strong> → CSS <code>transform: rotate() scale() translate()</code>, 3D graphics pipeline (model → world → camera → screen space), image processing filters</li>
</ul>
<p>If you ever want to build games, graphics, animations, data visualizations, or even just understand how CSS layout works at a deeper level -- geometry is your foundation.</p>
</div>
</div>
</div>
<!-- Table of Contents -->
<div class="container">
<div class="toc">
<h4>Table of Contents</h4>
<a href="#basic-shapes">1. Basic Shapes and Properties</a>
<a href="#angles">2. Angles</a>
<a href="#area-perimeter">3. Area and Perimeter</a>
<a href="#volume-surface-area">4. Volume and Surface Area</a>
<a href="#pythagorean">5. Pythagorean Theorem</a>
<a href="#trigonometry">6. Trigonometry Basics</a>
<a href="#coordinate-geometry">7. Coordinate Geometry</a>
<a href="#transformations">8. Transformations</a>
<a href="#quiz">9. Practice Quiz</a>
</div>
</div>
<!-- Main Content -->
<div class="container">
<!-- ============================================================ -->
<!-- SECTION 1: Basic Shapes and Properties -->
<!-- ============================================================ -->
<section id="basic-shapes">
<h2>1. Basic Shapes and Properties</h2>
<p>Geometry starts with the most fundamental building blocks: points, lines, and the shapes they form. Everything in geometry -- from simple triangles to complex 3D models -- is built from these primitives.</p>
<h3>Points, Lines, Rays, and Line Segments</h3>
<p>These are the atoms of geometry. Every shape is ultimately defined by points and the connections between them.</p>
<ul>
<li><strong>Point:</strong> A single location in space. It has no size, no width, no length -- just a position. We label points with capital letters: A, B, C.</li>
<li><strong>Line:</strong> An infinite collection of points extending forever in both directions. A line through points A and B is written as AB with a double-headed arrow above it. Lines never end.</li>
<li><strong>Ray:</strong> Starts at a point and extends forever in one direction. Think of a flashlight beam -- it has a starting point but no end.</li>
<li><strong>Line Segment:</strong> A piece of a line with two endpoints. It has a definite, measurable length. The segment from A to B is written AB with a bar above it.</li>
</ul>
<pre>
<span class="comment"> Point Line (infinite) Ray (one direction) Segment (finite)</span>
* <-----------> *-----------> *-----------*
A A B A A B
</pre>
<div class="tip-box">
<div class="label">Why This Matters for CS</div>
<p>In computer graphics, everything you draw on screen is made of points (vertices) connected by line segments (edges). A 3D model in a game is just thousands of points connected by segments forming triangles. Understanding these primitives is the foundation of rendering.</p>
</div>
<h3>Triangles</h3>
<p>The triangle is the most important polygon in geometry and in computer science. Every complex shape can be broken down into triangles -- this is why GPUs are optimized for triangle rendering.</p>
<table>
<thead>
<tr>
<th>Type</th>
<th>Definition</th>
<th>Key Property</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Equilateral</strong></td>
<td>All 3 sides equal</td>
<td>All angles are 60 degrees</td>
</tr>
<tr>
<td><strong>Isosceles</strong></td>
<td>2 sides equal</td>
<td>2 base angles are equal</td>
</tr>
<tr>
<td><strong>Scalene</strong></td>
<td>No sides equal</td>
<td>All angles different</td>
</tr>
<tr>
<td><strong>Right</strong></td>
<td>One angle is exactly 90 degrees</td>
<td>Pythagorean theorem applies</td>
</tr>
</tbody>
</table>
<pre>
<span class="comment"> Equilateral Isosceles Scalene Right</span>
/\ /\ /\ |\
/ \ / \ / \ | \
/ \ / \ / \ | \
/______\ /______\ /______\ |___\
60 60 60 70 70 40 50 60 70 90
</pre>
<p>A crucial fact: <strong>the angles in any triangle always sum to exactly 180 degrees.</strong> This is true regardless of the type of triangle. We will use this constantly.</p>
<h3>Quadrilaterals</h3>
<p>Quadrilaterals are four-sided polygons. Each type has specific properties that make them useful for different calculations.</p>
<table>
<thead>
<tr>
<th>Shape</th>
<th>Properties</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Square</strong></td>
<td>4 equal sides, 4 right angles (90 degrees). Diagonals are equal and bisect each other at right angles.</td>
</tr>
<tr>
<td><strong>Rectangle</strong></td>
<td>Opposite sides equal, 4 right angles. A "stretched" square. Diagonals are equal.</td>
</tr>
<tr>
<td><strong>Parallelogram</strong></td>
<td>Opposite sides parallel and equal. Opposite angles equal. Diagonals bisect each other.</td>
</tr>
<tr>
<td><strong>Trapezoid</strong></td>
<td>Exactly one pair of parallel sides (called bases). The non-parallel sides are called legs.</td>
</tr>
<tr>
<td><strong>Rhombus</strong></td>
<td>4 equal sides (like a "tilted" square). Opposite angles equal. Diagonals bisect each other at right angles.</td>
</tr>
</tbody>
</table>
<pre>
<span class="comment"> Square Rectangle Parallelogram Trapezoid Rhombus</span>
+------+ +----------+ ________ __________ /\
| | | | / / / \ / \
| | | | / / / \ / \
+------+ +----------+ /-------/ /--------------\ \ /
\ /
\/
</pre>
<h3>Circles</h3>
<p>A circle is the set of all points that are the same distance from a center point. That distance is the <strong>radius</strong>.</p>
<ul>
<li><strong>Radius (r):</strong> Distance from center to any point on the circle.</li>
<li><strong>Diameter (d):</strong> Distance across the circle through the center. Always d = 2r.</li>
<li><strong>Circumference (C):</strong> The distance around the circle (its perimeter). C = 2(pi)r.</li>
<li><strong>Chord:</strong> A line segment connecting any two points on the circle. The diameter is the longest possible chord.</li>
<li><strong>Arc:</strong> A portion of the circumference. Measured by angle or length.</li>
<li><strong>Sector:</strong> The "pie slice" region between two radii and an arc.</li>
<li><strong>Tangent:</strong> A line that touches the circle at exactly one point, perpendicular to the radius at that point.</li>
</ul>
<div class="tip-box">
<div class="label">Why This Matters for CS</div>
<p>Circles are everywhere in CS: collision detection (is a point within radius r of an object?), circular buffers in data structures, the unit circle in trigonometry for rotations, and even hashing algorithms that work modularly "wrapping around" like a circle.</p>
</div>
<h3>Polygons</h3>
<p>A polygon is a closed figure made of straight line segments. Triangles (3 sides) and quadrilaterals (4 sides) are the simplest, but polygons can have any number of sides.</p>
<table>
<thead>
<tr>
<th>Sides</th>
<th>Name</th>
<th>Sum of Interior Angles</th>
</tr>
</thead>
<tbody>
<tr><td>3</td><td>Triangle</td><td>180 degrees</td></tr>
<tr><td>4</td><td>Quadrilateral</td><td>360 degrees</td></tr>
<tr><td>5</td><td>Pentagon</td><td>540 degrees</td></tr>
<tr><td>6</td><td>Hexagon</td><td>720 degrees</td></tr>
<tr><td>7</td><td>Heptagon</td><td>900 degrees</td></tr>
<tr><td>8</td><td>Octagon</td><td>1080 degrees</td></tr>
<tr><td>n</td><td>n-gon</td><td>(n - 2) x 180 degrees</td></tr>
</tbody>
</table>
<div class="formula-box">
Sum of interior angles of an n-sided polygon = (n - 2) x 180 degrees<br>
Each interior angle of a regular n-gon = (n - 2) x 180 / n degrees
</div>
<p>A <strong>regular polygon</strong> has all sides equal and all angles equal. A <strong>convex polygon</strong> has all interior angles less than 180 degrees (no "dents"). These properties matter for CS algorithms like convex hull computation.</p>
</section>
<!-- ============================================================ -->
<!-- SECTION 2: Angles -->
<!-- ============================================================ -->
<section id="angles">
<h2>2. Angles</h2>
<p>An angle is formed when two rays share a common endpoint (called the vertex). Angles are measured in degrees (from 0 to 360) or radians (from 0 to 2(pi)). Understanding angle relationships is essential for everything from triangle solving to rotation in graphics.</p>
<h3>Types of Angles</h3>
<table>
<thead>
<tr>
<th>Type</th>
<th>Measure</th>
<th>Looks Like</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Acute</strong></td>
<td>Less than 90 degrees</td>
<td>A "sharp" angle</td>
</tr>
<tr>
<td><strong>Right</strong></td>
<td>Exactly 90 degrees</td>
<td>A perfect corner (L-shape)</td>
</tr>
<tr>
<td><strong>Obtuse</strong></td>
<td>Between 90 and 180 degrees</td>
<td>A "wide" angle</td>
</tr>
<tr>
<td><strong>Straight</strong></td>
<td>Exactly 180 degrees</td>
<td>A flat line</td>
</tr>
<tr>
<td><strong>Reflex</strong></td>
<td>Between 180 and 360 degrees</td>
<td>More than a half-turn</td>
</tr>
</tbody>
</table>
<pre>
<span class="comment"> Acute (45) Right (90) Obtuse (120) Straight (180) Reflex (270)</span>
/ | \ ___________ ___________
/ | \ |
/____ |_____ \____ |
|
</pre>
<h3>Complementary and Supplementary Angles</h3>
<p>These are pairs of angles with special relationships:</p>
<div class="formula-box">
Complementary angles: two angles that sum to 90 degrees<br>
Supplementary angles: two angles that sum to 180 degrees
</div>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> If one angle is 35 degrees, find its complement and supplement.</p>
<p><strong>Complement:</strong> 90 - 35 = 55 degrees</p>
<p><strong>Supplement:</strong> 180 - 35 = 145 degrees</p>
</div>
<h3>Vertical Angles</h3>
<p>When two lines cross, they form two pairs of <strong>vertical angles</strong> (also called "vertically opposite angles"). Vertical angles are always equal.</p>
<pre>
<span class="comment"> Two lines crossing form 4 angles:</span>
\ a / a = c (vertical angles)
\ / b = d (vertical angles)
b \ / d a + b = 180 (supplementary)
--------\ /--------
/ \
d / \ b
/ \
/ c \
</pre>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> Two lines intersect. One angle is 65 degrees. Find all four angles.</p>
<p>The vertical angle is also 65 degrees.</p>
<p>The supplementary angle is 180 - 65 = 115 degrees.</p>
<p>Its vertical angle is also 115 degrees.</p>
<p><strong>Answer:</strong> 65, 115, 65, 115 degrees.</p>
</div>
<h3>Angles in a Triangle</h3>
<div class="formula-box">
The three interior angles of any triangle sum to exactly 180 degrees.<br><br>
If two angles are known: third angle = 180 - (angle1 + angle2)
</div>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> A triangle has angles of 50 degrees and 70 degrees. Find the third angle.</p>
<p>Third angle = 180 - 50 - 70 = 60 degrees</p>
</div>
<h3>Interior Angles of Polygons</h3>
<div class="formula-box">
Sum of interior angles of an n-sided polygon = (n - 2) x 180 degrees
</div>
<p>This formula works because any polygon can be divided into (n - 2) triangles by drawing diagonals from one vertex. Since each triangle has angles summing to 180 degrees, the total is (n - 2) x 180.</p>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> What is the sum of interior angles of a hexagon (6 sides)?</p>
<p>Sum = (6 - 2) x 180 = 4 x 180 = 720 degrees</p>
<p><strong>Q:</strong> What is each interior angle of a regular hexagon?</p>
<p>Each angle = 720 / 6 = 120 degrees</p>
</div>
<div class="tip-box">
<div class="label">Why This Matters for CS</div>
<p>Angles are fundamental to rotation in computer graphics. When you rotate a sprite in a game, you are applying an angle. When a character "looks at" another character, the game engine calculates the angle between them. Radians (not degrees) are typically used in code because trig functions in most languages expect radians.</p>
</div>
<div class="warning-box">
<div class="label">Watch Out</div>
<p>Most programming languages (JavaScript, Python, C++) use <strong>radians</strong>, not degrees, for trigonometric functions. To convert: radians = degrees x (pi / 180). Forgetting this conversion is one of the most common bugs in graphics code.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 3: Area and Perimeter -->
<!-- ============================================================ -->
<section id="area-perimeter">
<h2>3. Area and Perimeter</h2>
<p><strong>Perimeter</strong> is the total distance around a shape (sum of all sides). <strong>Area</strong> is the amount of surface the shape covers, measured in square units (cm squared, m squared, pixels squared, etc.).</p>
<h3>Rectangle</h3>
<div class="formula-box">
Area = length x width<br>
Perimeter = 2 x (length + width)
</div>
<pre>
<span class="comment"> width (w)</span>
+----------+
| |
<span class="comment"> length | | A = l x w</span>
<span class="comment"> (l) | | P = 2(l + w)</span>
+----------+
</pre>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> A rectangle is 8 cm long and 5 cm wide. Find its area and perimeter.</p>
<p>Area = 8 x 5 = 40 cm squared</p>
<p>Perimeter = 2 x (8 + 5) = 2 x 13 = 26 cm</p>
</div>
<h3>Square</h3>
<div class="formula-box">
Area = side squared = s x s<br>
Perimeter = 4 x side = 4s
</div>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> Find the area and perimeter of a square with side length 6 cm.</p>
<p>Area = 6 x 6 = 36 cm squared</p>
<p>Perimeter = 4 x 6 = 24 cm</p>
</div>
<h3>Triangle</h3>
<div class="formula-box">
Area = (1/2) x base x height<br>
Perimeter = side1 + side2 + side3
</div>
<p>The <strong>height</strong> (or altitude) must be perpendicular to the base. It is not necessarily one of the sides -- sometimes you drop a perpendicular from the top vertex down to the base.</p>
<pre>
<span class="comment"> *</span>
<span class="comment"> /|\</span>
<span class="comment"> / | \ height (h)</span>
<span class="comment"> / | \</span>
<span class="comment"> / | \</span>
<span class="comment"> /____|____\</span>
<span class="comment"> base (b)</span>
<span class="comment"></span>
<span class="comment"> A = (1/2) x b x h</span>
</pre>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> A triangle has a base of 10 cm and a height of 7 cm. Find its area.</p>
<p>Area = (1/2) x 10 x 7 = 35 cm squared</p>
</div>
<h3>Circle</h3>
<div class="formula-box">
Area = pi x r squared (approximately 3.14159 x r x r)<br>
Circumference = 2 x pi x r = pi x d
</div>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> A circle has a radius of 4 cm. Find its area and circumference.</p>
<p>Area = pi x 4 x 4 = 16pi approximately equals 50.27 cm squared</p>
<p>Circumference = 2 x pi x 4 = 8pi approximately equals 25.13 cm</p>
</div>
<h3>Parallelogram</h3>
<div class="formula-box">
Area = base x height<br>
Perimeter = 2 x (base + side)
</div>
<p>Notice that the area formula looks like a rectangle's. That is because if you "cut" one end of a parallelogram and move it to the other end, you get a rectangle with the same base and height.</p>
<pre>
<span class="comment"> __________</span>
<span class="comment"> / / height (h) is perpendicular</span>
<span class="comment"> / h / to the base, NOT the slanted side</span>
<span class="comment"> /__________/</span>
<span class="comment"> base (b)</span>
</pre>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> A parallelogram has a base of 12 cm and a height of 5 cm. Find its area.</p>
<p>Area = 12 x 5 = 60 cm squared</p>
</div>
<h3>Trapezoid (Trapezium)</h3>
<div class="formula-box">
Area = (1/2) x (a + b) x h<br><br>
where a and b are the two parallel sides (bases) and h is the height between them
</div>
<pre>
<span class="comment"> ________ <-- top base (a)</span>
<span class="comment"> / \</span>
<span class="comment"> / h \ height is perpendicular</span>
<span class="comment"> / \ distance between bases</span>
<span class="comment"> /______________\ <-- bottom base (b)</span>
</pre>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> A trapezoid has parallel sides of 6 cm and 10 cm, with a height of 4 cm. Find its area.</p>
<p>Area = (1/2) x (6 + 10) x 4 = (1/2) x 16 x 4 = 32 cm squared</p>
</div>
<div class="warning-box">
<div class="label">Common Mistake</div>
<p>For parallelograms and trapezoids, the <strong>height</strong> is the perpendicular distance, not the length of the slanted side. If you use the slanted side instead of the true height, your answer will be wrong. Always look for or calculate the perpendicular height.</p>
</div>
<div class="tip-box">
<div class="label">Why This Matters for CS</div>
<p>Area calculations appear in collision detection (does a click land inside a shape?), UI layout engines (sizing elements), image processing (counting pixels in regions), and geographic information systems (calculating land areas). The "point in polygon" problem is a classic CS challenge.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 4: Volume and Surface Area -->
<!-- ============================================================ -->
<section id="volume-surface-area">
<h2>4. Volume and Surface Area</h2>
<p><strong>Volume</strong> measures the 3D space inside a solid shape (in cubic units). <strong>Surface area</strong> is the total area of all the outer faces. Think of volume as how much water a container holds, and surface area as how much wrapping paper you need to cover it.</p>
<h3>Cube</h3>
<div class="formula-box">
Volume = s cubed = s x s x s<br>
Surface Area = 6 x s squared (6 identical square faces)
</div>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> A cube has side length 3 cm. Find its volume and surface area.</p>
<p>Volume = 3 x 3 x 3 = 27 cm cubed</p>
<p>Surface Area = 6 x (3 x 3) = 6 x 9 = 54 cm squared</p>
</div>
<h3>Rectangular Prism (Box)</h3>
<div class="formula-box">
Volume = length x width x height<br>
Surface Area = 2(lw + lh + wh)
</div>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> A box is 5 cm long, 3 cm wide, and 4 cm tall. Find its volume and surface area.</p>
<p>Volume = 5 x 3 x 4 = 60 cm cubed</p>
<p>Surface Area = 2(5x3 + 5x4 + 3x4) = 2(15 + 20 + 12) = 2(47) = 94 cm squared</p>
</div>
<h3>Cylinder</h3>
<div class="formula-box">
Volume = pi x r squared x h<br>
Surface Area = 2 x pi x r squared + 2 x pi x r x h = 2(pi)r(r + h)<br><br>
(Two circular ends + the curved side that "unwraps" into a rectangle)
</div>
<pre>
<span class="comment"> _____</span>
<span class="comment"> / \ <-- top circle: area = pi x r squared</span>
<span class="comment"> | |</span>
<span class="comment"> | h | <-- curved surface "unwraps" to a rectangle:</span>
<span class="comment"> | | width = 2(pi)r, height = h</span>
<span class="comment"> \_____/ <-- bottom circle</span>
</pre>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> A cylinder has radius 3 cm and height 10 cm. Find its volume.</p>
<p>Volume = pi x 3 x 3 x 10 = 90pi approximately equals 282.74 cm cubed</p>
</div>
<h3>Sphere</h3>
<div class="formula-box">
Volume = (4/3) x pi x r cubed<br>
Surface Area = 4 x pi x r squared
</div>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> A sphere has radius 6 cm. Find its volume and surface area.</p>
<p>Volume = (4/3) x pi x 6 x 6 x 6 = (4/3) x 216pi = 288pi approximately equals 904.78 cm cubed</p>
<p>Surface Area = 4 x pi x 6 x 6 = 144pi approximately equals 452.39 cm squared</p>
</div>
<h3>Cone</h3>
<div class="formula-box">
Volume = (1/3) x pi x r squared x h<br>
Surface Area = pi x r squared + pi x r x l<br><br>
where l is the slant height: l = sqrt(r squared + h squared)
</div>
<p>Notice the cone volume is exactly 1/3 of a cylinder with the same base and height. This is not a coincidence -- it can be proven with calculus.</p>
<pre>
<span class="comment"> * <-- apex</span>
<span class="comment"> /|\</span>
<span class="comment"> / | \ l (slant height)</span>
<span class="comment"> / |h \</span>
<span class="comment"> / | \</span>
<span class="comment"> /____|____\</span>
<span class="comment"> r</span>
</pre>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> A cone has radius 4 cm and height 9 cm. Find its volume.</p>
<p>Volume = (1/3) x pi x 4 x 4 x 9 = (1/3) x 144pi = 48pi approximately equals 150.80 cm cubed</p>
</div>
<div class="tip-box">
<div class="label">Why This Matters for CS</div>
<p>3D volume and surface area calculations are essential in game physics (calculating buoyancy, mass from density), 3D printing (estimating material needed), and scientific computing. Bounding volumes (spheres, boxes) are used in collision detection because checking "is a point inside a sphere?" is much faster than checking complex shapes.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 5: Pythagorean Theorem -->
<!-- ============================================================ -->
<section id="pythagorean">
<h2>5. Pythagorean Theorem</h2>
<h3>What Is It and Why Does It Exist?</h3>
<p>The Pythagorean theorem answers one of the most practical questions in all of math: <strong>if I know two sides of a right triangle, how do I find the third?</strong> That is it. It is a tool for finding missing distances.</p>
<p>It only works on <strong>right triangles</strong> (triangles with one 90-degree angle). The formula says: the two shorter sides, when squared and added together, equal the longest side squared.</p>
<div class="formula-box">
a² + b² = c²<br><br>
c is the hypotenuse (the longest side, always opposite the right angle)<br>
a and b are the two legs (the sides that form the right angle)
</div>
<div class="memory-diagram"> |\
| \
a | \ c (hypotenuse -- longest side,
| \ always opposite the right angle)
| \
|_____\
b
a² + b² = c²</div>
<h3>Why Does It Work? (Visual Proof)</h3>
<p>This is not just a formula someone invented -- there is a beautiful geometric reason it is true. If you build a square on each side of a right triangle, the area of the two smaller squares adds up exactly to the area of the big square:</p>
<div class="memory-diagram"> +-------+
| |
| a²=9 | The square on side a (3x3) has area 9
| | The square on side b (4x4) has area 16
+-------+\ The square on side c (5x5) has area 25
|\ \
a | \ c \ 9 + 16 = 25
| \ \ a² + b² = c²
|___\--------+
b | | The two small squares TILE PERFECTLY
| b²=16 | into the big square. Always.
| | This is not a coincidence -- it is
+-------+ geometry forcing it to be true.
Try it yourself: 3² + 4² = 9 + 16 = 25 = 5²</div>
<h3>When Would I Actually Use This?</h3>
<div class="tip-box">
<div class="label">Real-World Situations</div>
<ul>
<li><strong>How far is that object?</strong> You walk 3 blocks east and 4 blocks north. How far are you from where you started? Straight-line distance = sqrt(3² + 4²) = 5 blocks.</li>
<li><strong>Will a TV fit?</strong> A TV is measured diagonally (the hypotenuse). A "55-inch TV" means the diagonal is 55 inches. You can figure out the actual width and height.</li>
<li><strong>Ladder against a wall:</strong> A 10-foot ladder leans against a wall, with its base 6 feet from the wall. How high does it reach? height = sqrt(10² - 6²) = sqrt(64) = 8 feet.</li>
<li><strong>Game development:</strong> How far is the enemy from the player? distance = sqrt((enemy_x - player_x)² + (enemy_y - player_y)²)</li>
</ul>
</div>
<h3>Finding the Hypotenuse</h3>
<p>If you know both legs, solve for the hypotenuse:</p>
<div class="formula-box">
c = sqrt(a squared + b squared)
</div>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> A right triangle has legs of 3 cm and 4 cm. Find the hypotenuse.</p>
<p>c = sqrt(3 squared + 4 squared) = sqrt(9 + 16) = sqrt(25) = 5 cm</p>
</div>
<h3>Finding a Leg</h3>
<p>If you know the hypotenuse and one leg, rearrange to find the other leg:</p>
<div class="formula-box">
a = sqrt(c squared - b squared)
</div>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> A right triangle has a hypotenuse of 13 cm and one leg of 5 cm. Find the other leg.</p>
<p>a = sqrt(13 squared - 5 squared) = sqrt(169 - 25) = sqrt(144) = 12 cm</p>
</div>
<h3>Pythagorean Triples</h3>
<p>Some right triangles have all integer side lengths. These are called <strong>Pythagorean triples</strong>. Memorizing a few common ones saves time:</p>
<table>
<thead>
<tr>
<th>Triple (a, b, c)</th>
<th>Verification</th>
<th>Multiples</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>3, 4, 5</strong></td>
<td>9 + 16 = 25</td>
<td>6-8-10, 9-12-15, 12-16-20, ...</td>
</tr>
<tr>
<td><strong>5, 12, 13</strong></td>
<td>25 + 144 = 169</td>
<td>10-24-26, 15-36-39, ...</td>
</tr>
<tr>
<td><strong>8, 15, 17</strong></td>
<td>64 + 225 = 289</td>
<td>16-30-34, ...</td>
</tr>
<tr>
<td><strong>7, 24, 25</strong></td>
<td>49 + 576 = 625</td>
<td>14-48-50, ...</td>
</tr>
</tbody>
</table>
<div class="tip-box">
<div class="label">Tip</div>
<p>Any multiple of a Pythagorean triple is also a triple. If 3-4-5 works, then 6-8-10 works (just multiply each by 2), and 30-40-50 works (multiply by 10). This is because scaling all sides by the same factor preserves the right angle.</p>
</div>
<h3>The Distance Formula</h3>
<p>The distance formula is the Pythagorean theorem in disguise. To find the distance between two points on a coordinate plane, you form a right triangle where the horizontal and vertical distances are the legs.</p>
<div class="formula-box">
Distance = sqrt((x2 - x1) squared + (y2 - y1) squared)
</div>
<pre>
<span class="comment"> (x2, y2) *</span>
<span class="comment"> |\</span>
<span class="comment"> | \ d = distance (hypotenuse)</span>
<span class="comment"> (y2 - y1)| d\</span>
<span class="comment"> | \</span>
<span class="comment"> |____\</span>
<span class="comment"> (x1, y1) * * (x2, y1)</span>
<span class="comment"> (x2 - x1)</span>
</pre>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> Find the distance between points (1, 2) and (4, 6).</p>
<p>d = sqrt((4 - 1) squared + (6 - 2) squared)</p>
<p>d = sqrt(3 squared + 4 squared) = sqrt(9 + 16) = sqrt(25) = 5</p>
<p>It is a 3-4-5 triangle!</p>
</div>
<div class="example-box">
<div class="label">Example</div>
<p><strong>Q:</strong> Find the distance between (-2, 3) and (1, 7).</p>
<p>d = sqrt((1 - (-2)) squared + (7 - 3) squared)</p>
<p>d = sqrt(3 squared + 4 squared) = sqrt(9 + 16) = sqrt(25) = 5</p>
</div>
<div class="tip-box">
<div class="label">Why This Matters for CS</div>
<p>The Pythagorean theorem and distance formula are used constantly in CS: calculating distance between game objects, nearest-neighbor searches, k-means clustering (machine learning), pathfinding algorithms (A*), and determining if two circles overlap (compare distance between centers to sum of radii). The squared distance is often used instead of actual distance to avoid the expensive square root operation.</p>
</div>
<div class="warning-box">
<div class="label">Performance Tip</div>
<p>In code, computing <code>sqrt()</code> is slow. When you only need to compare distances (e.g., "is A closer than B?"), compare the <strong>squared</strong> distances instead: <code>dx*dx + dy*dy</code>. If dist1_squared < dist2_squared, then dist1 < dist2. This optimization matters in game loops running 60 times per second.</p>
</div>
<div class="tip-box">
<div class="label">Beyond Straight Lines: Manhattan Distance</div>
<p>The distance formula above gives the <strong>Euclidean distance</strong> (straight line). But in grid-based problems (LeetCode, chess, city navigation), you often need the <strong>Manhattan distance</strong> instead: <code>|x2-x1| + |y2-y1|</code>. This measures the distance walking along grid lines, not cutting diagonally. See the full comparison in the <a href="#coordinate-geometry">Coordinate Geometry section</a> below.</p>
</div>
</section>
<!-- ============================================================ -->
<!-- SECTION 6: Trigonometry Basics -->
<!-- ============================================================ -->
<section id="trigonometry">
<h2>6. Trigonometry Basics</h2>
<h3>What Problem Does Trig Solve?</h3>
<p>The Pythagorean theorem connects <em>sides to sides</em>. But what if you know an <strong>angle</strong> and a <strong>side</strong>, and need to find another side? Or you know two sides and need the angle? That is what trigonometry does. It connects <strong>angles to side lengths</strong>.</p>
<p>Here is the real-world problem: you are standing 50 meters from a building. You look up at the top and measure the angle is 35 degrees. How tall is the building? You cannot use Pythagoras -- you only know one side and one angle, not two sides. You need trig.</p>
<div class="tip-box">
<div class="label">The Key Insight Behind All of Trig</div>
<p>Here is the beautiful idea: <strong>in a right triangle, once you fix an angle, the RATIOS between the sides are always the same, no matter how big or small the triangle is.</strong></p>
<p>A tiny right triangle with a 30-degree angle and a huge right triangle with a 30-degree angle have sides of different lengths, but the <em>ratios</em> between their sides are identical. Sine, cosine, and tangent are just names for these fixed ratios.</p>
</div>
<div class="memory-diagram"> All 30-degree right triangles have the same ratios:
Small triangle: Big triangle:
|\ |\
| \ | \
1 | \ 2 5 | \ 10
| \ | \
|30° \ |30° \
|_____\ |_____\
1.73 8.66
opposite / hypotenuse = 1/2 = 0.5 = sin(30°)
opposite / hypotenuse = 5/10 = 0.5 = sin(30°)
Same ratio! The triangle got bigger but the RATIO stayed the same.
That is why sin(30°) = 0.5 no matter what triangle you use.</div>
<h3>SOH CAH TOA</h3>
<p>SOHCAHTOA is a mnemonic for the three ratios. Each one divides two specific sides of a right triangle:</p>
<div class="formula-box">
<strong>SOH:</strong> sin(theta) = Opposite / Hypotenuse<br>
<strong>CAH:</strong> cos(theta) = Adjacent / Hypotenuse<br>
<strong>TOA:</strong> tan(theta) = Opposite / Adjacent<br><br>
Also: tan(theta) = sin(theta) / cos(theta)
</div>
<div class="memory-diagram"> Which sides are which? It depends on your angle.
|\
| \
Opposite | \ Hypotenuse Opposite = the side ACROSS from your angle
(to | \ Adjacent = the side TOUCHING your angle
angle | \ Hypotenuse = the longest side (always
theta) |_____\ theta opposite the right angle)
Adjacent
(to angle theta)</div>
<h3>What Each Ratio Actually Tells You</h3>
<ul>
<li><strong>sin(angle)</strong> = "what fraction of the hypotenuse is the opposite side?" If sin(30) = 0.5, that means the opposite side is always half the hypotenuse in a 30-degree triangle.</li>
<li><strong>cos(angle)</strong> = "what fraction of the hypotenuse is the adjacent side?" If cos(60) = 0.5, the adjacent side is half the hypotenuse.</li>
<li><strong>tan(angle)</strong> = "how many times bigger is the opposite side than the adjacent side?" If tan(45) = 1, they are equal. If tan(60) = 1.73, the opposite side is 1.73 times the adjacent.</li>
</ul>
<div class="example-box">
<div class="label">When to Use Which Ratio</div>
<p>Look at what you <strong>know</strong> and what you <strong>want</strong>:</p>
<ul>
<li>Know hypotenuse, want opposite? Use <strong>sin</strong> (SOH)</li>
<li>Know hypotenuse, want adjacent? Use <strong>cos</strong> (CAH)</li>
<li>Know adjacent, want opposite (or vice versa)? Use <strong>tan</strong> (TOA)</li>
</ul>
<p>Just ask: "which two sides am I dealing with?" and pick the ratio that uses those two.</p>
</div>
<div class="warning-box">
<div class="label">Watch Out</div>
<p>The "opposite" and "adjacent" sides <strong>change depending on which angle you are looking at</strong>. Always identify your angle first, then determine which side is across from it (opposite) and which side touches it (adjacent). The hypotenuse is always the same.</p>
</div>
<h3>Common Angle Values</h3>
<p>Memorize these. They come up constantly in math and CS.</p>
<table>
<thead>
<tr>
<th>Angle</th>
<th>sin</th>
<th>cos</th>
<th>tan</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>0 degrees</strong></td>
<td>0</td>
<td>1</td>
<td>0</td>
</tr>
<tr>
<td><strong>30 degrees</strong></td>
<td>1/2 = 0.500</td>
<td>sqrt(3)/2 = 0.866</td>
<td>1/sqrt(3) = 0.577</td>
</tr>
<tr>
<td><strong>45 degrees</strong></td>
<td>sqrt(2)/2 = 0.707</td>
<td>sqrt(2)/2 = 0.707</td>
<td>1</td>
</tr>
<tr>
<td><strong>60 degrees</strong></td>
<td>sqrt(3)/2 = 0.866</td>
<td>1/2 = 0.500</td>
<td>sqrt(3) = 1.732</td>
</tr>
<tr>
<td><strong>90 degrees</strong></td>
<td>1</td>
<td>0</td>
<td>undefined</td>
</tr>
</tbody>
</table>
<div class="tip-box">
<div class="label">Memory Trick</div>
<p>For sine, the values at 0, 30, 45, 60, 90 degrees follow a pattern: sqrt(0)/2, sqrt(1)/2, sqrt(2)/2, sqrt(3)/2, sqrt(4)/2 which simplifies to 0, 1/2, sqrt(2)/2, sqrt(3)/2, 1. Cosine is the same pattern in reverse.</p>
</div>
<h3>Solving for a Side</h3>
<div class="example-box">
<div class="label">Example 1 -- Finding the opposite side</div>
<p><strong>Q:</strong> A right triangle has a hypotenuse of 10 cm and an angle of 30 degrees. Find the side opposite to the 30-degree angle.</p>
<p>sin(30) = opposite / hypotenuse</p>
<p>0.5 = opposite / 10</p>
<p>opposite = 10 x 0.5 = 5 cm</p>
</div>
<div class="example-box">
<div class="label">Example 2 -- Finding the adjacent side</div>
<p><strong>Q:</strong> A right triangle has a hypotenuse of 10 cm and an angle of 30 degrees. Find the side adjacent to the 30-degree angle.</p>
<p>cos(30) = adjacent / hypotenuse</p>
<p>0.866 = adjacent / 10</p>
<p>adjacent = 10 x 0.866 = 8.66 cm</p>
</div>
<div class="example-box">
<div class="label">Example 3 -- Using tangent</div>
<p><strong>Q:</strong> A ladder leans against a wall. The base is 6 m from the wall, and the angle at the ground is 60 degrees. How high up the wall does the ladder reach?</p>