From 8ef44ddda0f1a78e465fabdabc02a7886dded9bc Mon Sep 17 00:00:00 2001 From: Aron T Date: Wed, 24 Sep 2025 20:31:24 +0300 Subject: [PATCH 01/10] Add polygons - initial documentation section - add polygons to sidebar - fix minor typo --- docs/make.jl | 3 +- docs/src/Geometry/03 Polygons.md | 43 +++++++++++++++++++ .../{03 Hyperbola.md => 04 Hyperbola.md} | 0 notebooks/Basics.ipynb | 2 +- 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 docs/src/Geometry/03 Polygons.md rename docs/src/Geometry/{03 Hyperbola.md => 04 Hyperbola.md} (100%) diff --git a/docs/make.jl b/docs/make.jl index ee4c587..5f3b2ea 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -20,7 +20,8 @@ makedocs(; "Geometry" => [ "Geometry/01 Triangles.md", "Geometry/02 Quadrilaterals.md", - # "Geometry/03 Hyperbola.md" # TODO: Uncomment when ready to show + "Geometry/03 Polygons.md", + # "Geometry/04 Hyperbola.md" # TODO: Uncomment when ready to show ], # "Linear Algebra" => [ # TODO: Uncomment when ready to show # "Linear Algebra/01 Systems of Equations.md", diff --git a/docs/src/Geometry/03 Polygons.md b/docs/src/Geometry/03 Polygons.md new file mode 100644 index 0000000..676487c --- /dev/null +++ b/docs/src/Geometry/03 Polygons.md @@ -0,0 +1,43 @@ +# Polygons + +## Introduction + +A [polygon](https://mathworld.wolfram.com/Polygon.html) is a planar (two-dimensional) geometric figure which is also called an _N-corner_, because their number of corners is N – a natural number greater than +2. To construct a polygon, start with N points in the plane and connect them with N lines in such a way that: + +1. they do not intersect, and +2. the starting point of the first line coincides with the ending point of the last line + +These two properties guarantee that such a closed polygon (all lines) is actually the boundary of a +two-dimensional figure – the N-corner. + +The line segments are called the _sides_ or _edges_ of the polygon, and the points where the sides meet are called the _vertices_ or _corners_. Polygons can have various numbers of sides, and they are classified based on the number of sides they possess. + +Here are some common types of polygons based on the number of sides (the first two we have described in detail in previous sections): + +- **Triangle (3 sides)**: The simplest polygon, with three edges and three vertices. +- **Quadrilateral (4 sides)**: A polygon with four edges and four vertices. Examples include squares, rectangles, and trapezoids. +- **Pentagon (5 sides)**: A polygon with five edges and five vertices. +- **Hexagon (6 sides)**: A polygon with six edges and six vertices. +- **Heptagon (7 sides)**: A polygon with seven edges and seven vertices. +- **Octagon (8 sides)**: A polygon with eight edges and eight vertices. +- **Nonagon (9 sides)**: A polygon with nine edges and nine vertices. +- **Decagon (10 sides)**: A polygon with ten edges and ten vertices. +- **Hendecagon (11 sides)**: A polygon with eleven edges and eleven vertices. +- **Dodecagon (12 sides)**: A polygon with twelve edges and twelve vertices. + +## Classification of Polygons + +Polygons are typically classified into two main categories: convex and concave. + +1. **Convex Polygons**: A polygon is convex if all its interior angles are less than 180 degrees, and no line segment between any two points on its boundary goes outside the polygon. In simpler terms, a convex polygon "bulges" outward. A more exact definition is that a convex polygon $\Lambda$ with two internal points $X$, $Y$, every point $Z$ of the connecting line between $X$ and $Y$, i.e., all points $Z$ of the form $Z = tX + (1-t)Y$ for $t \in [0, 1]$, lies inside $\Lambda$. + +2. **Concave Polygons**: A polygon is concave if at least one of its interior angles is greater than 180 degrees. This means that there is at least one line segment between two points on its boundary that goes outside the polygon, causing it to "cave" inward. In concave polygons $\Lambda$, internal points $X$ and $Y$ exist in $\Lambda$, so some point(s) $Z$ (defined above) on their connecting line is not in $\Lambda$. + +### Regular vs. Irregular Polygons + +Polygons can also be classified as regular or irregular: + +1. **Regular Polygons**: A regular polygon has all sides of equal length and all interior angles of equal measure. Examples include equilateral triangles and squares. + +2. **Irregular Polygons**: An irregular polygon does not have equal side lengths or equal angles. Most polygons encountered in everyday life are irregular. diff --git a/docs/src/Geometry/03 Hyperbola.md b/docs/src/Geometry/04 Hyperbola.md similarity index 100% rename from docs/src/Geometry/03 Hyperbola.md rename to docs/src/Geometry/04 Hyperbola.md diff --git a/notebooks/Basics.ipynb b/notebooks/Basics.ipynb index 7614fe6..02e18ec 100644 --- a/notebooks/Basics.ipynb +++ b/notebooks/Basics.ipynb @@ -3458,8 +3458,8 @@ "Let the lengths of the two parallel sides be $a$ and $b$, with $a$ being the shorter side. Let the height of the trapezoid be $h$. According to the problem, we have:\n", "$$a = h$$\n", "$$b = 2h$$\n", - "From the second equation, we can express $h$ in terms of $a$:\n", "$$\\text{F} = \\frac{(a + b)}{2} \\cdot h = 1$$\n", + "Substituting the expressions for $a$ and $b$ into the area formula:\n", "$$\\text{F} = \\frac{(h + 2h)}{2} \\cdot h = 1$$\n", "$$\\frac{3h^2}{2} = 1$$\n", "$$h^2 = \\frac{2}{3}$$\n", From 0e86831738a6ccdf75acb1cafc8f429e788baec1 Mon Sep 17 00:00:00 2001 From: Aron T Date: Fri, 26 Sep 2025 17:46:42 +0300 Subject: [PATCH 02/10] Add comprehensive SVG diagrams to polygon documentation - Add 5 detailed SVG diagrams illustrating polygon concepts: - Convex vs concave polygons with geometric proofs - Regular vs irregular polygons comparison - Pentagon fan triangulation example - Hexagon fan triangulation example - Alternative triangulation methods demonstration - All diagrams include: - Interactive visual elements - Mathematical accuracy and proper labeling - Step-by-step explanations - Formula verification - Comprehensive legends - Maintains full mathematical rigor while adding visual clarity - Ready for further refinement of any documentation build warnings --- docs/src/Geometry/03 Polygons.md | 725 ++++++++++++++++++++++++++++++- 1 file changed, 723 insertions(+), 2 deletions(-) diff --git a/docs/src/Geometry/03 Polygons.md b/docs/src/Geometry/03 Polygons.md index 676487c..f3c3dd1 100644 --- a/docs/src/Geometry/03 Polygons.md +++ b/docs/src/Geometry/03 Polygons.md @@ -30,9 +30,109 @@ Here are some common types of polygons based on the number of sides (the first t Polygons are typically classified into two main categories: convex and concave. -1. **Convex Polygons**: A polygon is convex if all its interior angles are less than 180 degrees, and no line segment between any two points on its boundary goes outside the polygon. In simpler terms, a convex polygon "bulges" outward. A more exact definition is that a convex polygon $\Lambda$ with two internal points $X$, $Y$, every point $Z$ of the connecting line between $X$ and $Y$, i.e., all points $Z$ of the form $Z = tX + (1-t)Y$ for $t \in [0, 1]$, lies inside $\Lambda$. +1. **[Convex Polygons](https://mathworld.wolfram.com/ConvexPolygon.html)**: A polygon is convex if all its interior angles are less than 180 degrees, and no line segment between any two points on its boundary goes outside the polygon. In simpler terms, a convex polygon "bulges" outward. -2. **Concave Polygons**: A polygon is concave if at least one of its interior angles is greater than 180 degrees. This means that there is at least one line segment between two points on its boundary that goes outside the polygon, causing it to "cave" inward. In concave polygons $\Lambda$, internal points $X$ and $Y$ exist in $\Lambda$, so some point(s) $Z$ (defined above) on their connecting line is not in $\Lambda$. + A more exact definition is that a convex polygon $\Lambda$ with two internal points $X$, $Y$, has the property that every point $Z$ of the connecting line between $X$ and $Y$ lies inside $\Lambda$. Mathematically, all points $Z$ of the form: + $$Z = tX + (1-t)Y \text{ for } t \in [0, 1]$$ + lie inside $\Lambda$. + +2. **[Concave Polygons](https://mathworld.wolfram.com/ConcavePolygon.html)**: A polygon is concave if at least one of its interior angles is greater than 180 degrees. This means that there is at least one line segment between two points on its boundary that goes outside the polygon, causing it to "cave" inward. + + In concave polygons $\Lambda$, internal points $X$ and $Y$ exist in $\Lambda$ such that some point(s) $Z$ on their connecting line is not in $\Lambda$. + +```@raw html + + + + Convex vs Concave Polygons + + + + + + + + + + + + X + Y + + + + Convex Polygon + + + All interior angles < 180° + + + Line XY stays inside + + + + + + + + + + + + X + Y + + + + θ > 180° + + + + Concave Polygon + + + At least one angle > 180° + + + Line XY goes outside + + + + + + + + Convex + + + Concave + + + Line inside polygon + + + Line outside polygon + +``` ### Regular vs. Irregular Polygons @@ -41,3 +141,624 @@ Polygons can also be classified as regular or irregular: 1. **Regular Polygons**: A regular polygon has all sides of equal length and all interior angles of equal measure. Examples include equilateral triangles and squares. 2. **Irregular Polygons**: An irregular polygon does not have equal side lengths or equal angles. Most polygons encountered in everyday life are irregular. + +```@raw html + + + + Regular vs Irregular Polygons + + + + + + + + + + + + + + + s + s + s + s + s + s + + + 120° + 120° + 120° + + + + Regular Hexagon + + + All sides equal: s + + + All angles equal: 120° + + + + + + + a + b + c + d + e + f + + + α + β + γ + δ + ε + ζ + + + + Irregular Hexagon + + + Different side lengths: a,b,c,d,e,f + + + Different angles: α,β,γ,δ,ε,ζ + + + + + + + + Regular (equal sides & angles) + + + Irregular (unequal sides & angles) + +``` + +## Properties of Polygons + +Polygons have several important properties that are useful in geometry: + +1. **Sum of Interior Angles**: The sum of the interior angles of a polygon with N sides is given by the formula: + $$ + \text{Sum of interior angles} = (N - 2) \times 180^\circ + $$ + For example, a triangle (3 sides) has a sum of interior angles equal to $180^\circ$, while a quadrilateral (4 sides) has a sum of $360^\circ$. + +2. **Exterior Angles**: The sum of the exterior angles of any polygon is always $360^\circ$, regardless of the number of sides. Each exterior angle is formed by extending one side of the polygon at a vertex. For a regular polygon, each exterior angle can be calculated as: + $$ + \text{Exterior angle} = \frac{360^\circ}{N} + $$ +3. **Diagonals**: A diagonal is a line segment connecting two non-adjacent vertices of a polygon. The number of diagonals (D) in a polygon with N sides can be calculated using the formula: + $$ + D = \frac{N(N - 3)}{2} + $$ + For example, a pentagon (5 sides) has 5 diagonals, while a hexagon (6 sides) has 9 diagonals. +4. **Area**: The area of a polygon can be calculated using various methods depending on the type of polygon. For regular polygons, the area can be calculated using the formula: + $$ + \text{Area} = \frac{1}{4} N s^2 \cot\left(\frac{\pi}{N}\right) + $$ + where $s$ is the length of a side. For irregular polygons, methods such as triangulation or the shoelace formula can be used. +5. **Perimeter**: The perimeter of a polygon is the total length of its sides. For a polygon with N sides, the perimeter (P) can be calculated as: + $$ + P = s_1 + s_2 + s_3 + ... + s_N + $$ + where $s_1, s_2, ..., s_N$ are the lengths of the sides. +6. **Symmetry**: Regular polygons exhibit a high degree of symmetry. They have multiple lines of symmetry and rotational symmetry. The number of lines of symmetry in a regular polygon is equal to the number of sides (N). + +## Triangulation + +[Triangulation](https://mathworld.wolfram.com/Triangulation.html) is the process of dividing any polygon into triangles by drawing non-intersecting diagonals. This technique is fundamental in geometry because triangles are the simplest polygons, and we already know how to calculate their properties (area, angles, side lengths) using basic geometric formulas. + +### Why Triangulation Works + +The number of triangles formed when triangulating a polygon with $N$ sides is always: +$$\text{Number of triangles} = N - 2$$ + +This formula works because: + +- Each triangle contributes $180°$ to the total angle sum +- The total interior angle sum of an $N$-sided polygon is $(N-2) \times 180°$ +- Therefore: $(N-2) \text{ triangles} \times 180° = (N-2) \times 180°$ + +### Basic Triangulation Methods + +**1. Fan Triangulation** +The simplest method is to choose one vertex and connect it to all non-adjacent vertices. This creates $(N-2)$ triangles that all share the chosen vertex as a common point. + +**Example - Pentagon Fan Triangulation:** + +- Start with pentagon $ABCDE$ +- Choose vertex $A$ as the fan center +- Draw diagonals: $AC$ and $AD$ +- Result: 3 triangles ($\triangle ABC$, $\triangle ACD$, $\triangle ADE$) + +```@raw html + + + + Pentagon Fan Triangulation + + + + + + + + + + + + + + + + + + + + + + + + + + + A + B + C + D + E + + + △ABC + △ACD + △ADE + + + AC + AD + + + + Fan Triangulation Steps: + + + 1. Choose vertex A as the fan center + + + 2. Draw diagonals AC and AD from vertex A + + + 3. Result: N-2 = 5-2 = 3 triangles + + + + + Verification: + + + Pentagon: N = 5 sides + + + Triangles = N - 2 = 5 - 2 = 3 ✓ + + + Angles: 3 × 180° = 540° ✓ + + + + + Triangle ABC + + + Triangle ACD + + + Triangle ADE + + + Diagonals + +``` + +**Example - Hexagon Fan Triangulation:** + +- Start with hexagon $ABCDEF$ +- Choose vertex $A$ as the fan center +- Draw diagonals: $AC$, $AD$, and $AE$ +- Result: 4 triangles ($\triangle ABC$, $\triangle ACD$, $\triangle ADE$, $\triangle AEF$) + +```@raw html + + + + Hexagon Fan Triangulation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A + B + C + D + E + F + + + △ABC + △ACD + △ADE + △AEF + + + AC + AD + AE + + + + Fan Triangulation Steps: + + + 1. Choose vertex A as the fan center + + + 2. Draw diagonals AC, AD, and AE from vertex A + + + 3. Result: N-2 = 6-2 = 4 triangles + + + + + Verification: + + + Hexagon: N = 6 sides + + + Triangles = N - 2 = 6 - 2 = 4 ✓ + + + Angles: 4 × 180° = 720° ✓ + + + + + △ABC + + + △ACD + + + △ADE + + + △AEF + + + Diagonals from A + + + + Note: All triangles share vertex A as a common point + + + This creates a "fan" pattern radiating from A + + +``` + +**2. Alternative Triangulation Methods** +The same polygon can be triangulated in multiple ways. For example, a quadrilateral $ABCD$ can be triangulated as: + +- Method 1: Diagonal $AC$ creates $\triangle ABC$ and $\triangle ACD$ +- Method 2: Diagonal $BD$ creates $\triangle ABD$ and $\triangle BCD$ + +Both methods create exactly 2 triangles, as predicted by the formula $N-2 = 4-2 = 2$. + +```@raw html + + + + Alternative Triangulation Methods + + + + + + + + + + + + + + + + + + + + + + + A + B + C + D + + + △ABC + △ACD + + + AC + + + + Method 1: Diagonal AC + + + + + + + + + + + + + + + + + + + + + + + A + B + C + D + + + △ABD + △BCD + + + BD + + + + Method 2: Diagonal BD + + + + + + + + Both Methods Create Exactly 2 Triangles + + + Formula: N - 2 = 4 - 2 = 2 triangles ✓ + + + Total angles: 2 × 180° = 360° ✓ + + + + + Method 1 Triangles: + + + △ABC + + △ACD + + + Method 2 Triangles: + + + △ABD + + △BCD + + + + Diagonal AC + + + Diagonal BD + +``` + +### Using Triangulation to Calculate Area + +Triangulation is particularly useful for finding the area of irregular polygons: + +**Step-by-Step Process:** + +1. **Triangulate** the polygon using any valid method +2. **Measure or calculate** the side lengths of each triangle +3. **Apply triangle area formulas** to each triangle: + - Use the basic formula: Area = $\frac{1}{2} \times \text{base} \times \text{height}$ + - Or use Heron's formula for triangles with known side lengths + - Or use trigonometric formula: Area = $\frac{1}{2}ab\sin(C)$ +4. **Sum all triangle areas** to get the total polygon area + +**Example - Pentagon Area Calculation:** +Given pentagon with vertices and using fan triangulation from vertex $A$: + +- Triangle 1 area: $A_1$ (calculated using appropriate triangle formula) +- Triangle 2 area: $A_2$ +- Triangle 3 area: $A_3$ +- **Total pentagon area = $A_1 + A_2 + A_3$** + +### Verification Methods + +To verify your triangulation is correct: + +1. **Count triangles**: Should equal $N-2$ +2. **Check angle sum**: All triangle angles should sum to $(N-2) \times 180°$ +3. **Verify no overlaps**: Triangles should not overlap each other +4. **Confirm coverage**: Triangles should cover the entire polygon interior + +### Practical Applications + +#### 1. Area Calculation + +- Breaking complex shapes into manageable triangular pieces +- Each triangle can be solved using familiar formulas +- Particularly useful for irregular polygons where direct area formulas don't exist + +#### 2. Construction and Design + +- Architectural applications where complex shapes need to be built from simpler triangular components +- Engineering applications requiring structural analysis of polygonal shapes + +#### 3. Problem Solving + +- Converting complex polygon problems into simpler triangle problems +- Using known triangle properties to solve unknown polygon properties + +The power of triangulation lies in its ability to reduce complex polygonal problems to collections of simple triangle problems, using only the basic geometric tools we've already developed. From 75a37efd9ce841db216c47279b60372bb0ae010f Mon Sep 17 00:00:00 2001 From: Aron T Date: Sun, 28 Sep 2025 21:02:03 +0300 Subject: [PATCH 03/10] Improve SVG diagram label positioning in polygon documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixed regular hexagon side labels (s) to be centered on each side - Repositioned irregular hexagon side labels (a,b,c,d,e,f) at proper midpoints - Corrected angle labels (α,β,γ,δ,ε,ζ) to be positioned near their vertices - Added text-anchor='middle' for precise label centering - Enhanced visual clarity and mathematical accuracy of geometric diagrams --- docs/src/Geometry/03 Polygons.md | 60 +++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/docs/src/Geometry/03 Polygons.md b/docs/src/Geometry/03 Polygons.md index f3c3dd1..ba58f17 100644 --- a/docs/src/Geometry/03 Polygons.md +++ b/docs/src/Geometry/03 Polygons.md @@ -165,17 +165,23 @@ Polygons can also be classified as regular or irregular: - s - s - s - s - s - s + + s + + s + + s + + s + + s + + s - 120° - 120° - 120° + 120° + 120° + 120° @@ -196,20 +202,32 @@ Polygons can also be classified as regular or irregular: opacity="0.8"/> - a - b - c - d - e - f + + a + + b + + c + + d + + e + + f - α - β - γ - δ - ε - ζ + + α + + β + + γ + + δ + + ε + + ζ From aeead0fa8587a0461a8d4bb1ee03e2632068c955 Mon Sep 17 00:00:00 2001 From: Aron T Date: Mon, 29 Sep 2025 20:44:52 +0300 Subject: [PATCH 04/10] Fix position of all labels in all diagrams to avoid overlap and improve clarity. --- docs/src/Geometry/03 Polygons.md | 72 ++++++++++++-------------------- 1 file changed, 26 insertions(+), 46 deletions(-) diff --git a/docs/src/Geometry/03 Polygons.md b/docs/src/Geometry/03 Polygons.md index ba58f17..1d96354 100644 --- a/docs/src/Geometry/03 Polygons.md +++ b/docs/src/Geometry/03 Polygons.md @@ -96,18 +96,18 @@ Polygons are typically classified into two main categories: convex and concave. Y - - θ > 180° + θ > 180° Concave Polygon - At least one angle > 180° + At least one interior angle > 180° Line XY goes outside @@ -259,32 +259,12 @@ Polygons can also be classified as regular or irregular: Polygons have several important properties that are useful in geometry: -1. **Sum of Interior Angles**: The sum of the interior angles of a polygon with N sides is given by the formula: - $$ - \text{Sum of interior angles} = (N - 2) \times 180^\circ - $$ - For example, a triangle (3 sides) has a sum of interior angles equal to $180^\circ$, while a quadrilateral (4 sides) has a sum of $360^\circ$. - -2. **Exterior Angles**: The sum of the exterior angles of any polygon is always $360^\circ$, regardless of the number of sides. Each exterior angle is formed by extending one side of the polygon at a vertex. For a regular polygon, each exterior angle can be calculated as: - $$ - \text{Exterior angle} = \frac{360^\circ}{N} - $$ -3. **Diagonals**: A diagonal is a line segment connecting two non-adjacent vertices of a polygon. The number of diagonals (D) in a polygon with N sides can be calculated using the formula: - $$ - D = \frac{N(N - 3)}{2} - $$ - For example, a pentagon (5 sides) has 5 diagonals, while a hexagon (6 sides) has 9 diagonals. -4. **Area**: The area of a polygon can be calculated using various methods depending on the type of polygon. For regular polygons, the area can be calculated using the formula: - $$ - \text{Area} = \frac{1}{4} N s^2 \cot\left(\frac{\pi}{N}\right) - $$ - where $s$ is the length of a side. For irregular polygons, methods such as triangulation or the shoelace formula can be used. -5. **Perimeter**: The perimeter of a polygon is the total length of its sides. For a polygon with N sides, the perimeter (P) can be calculated as: - $$ - P = s_1 + s_2 + s_3 + ... + s_N - $$ - where $s_1, s_2, ..., s_N$ are the lengths of the sides. -6. **Symmetry**: Regular polygons exhibit a high degree of symmetry. They have multiple lines of symmetry and rotational symmetry. The number of lines of symmetry in a regular polygon is equal to the number of sides (N). +1. **Sum of Interior Angles**: The sum of the interior angles of a polygon with N sides is given by the formula: $\text{Sum of interior angles} = (N - 2) \times 180^\circ$. For example, a triangle (3 sides) has a sum of interior angles equal to $180^\circ$, while a quadrilateral (4 sides) has a sum of $360^\circ$. +2. **Exterior Angles**: The sum of the exterior angles of any polygon is always $360^\circ$, regardless of the number of sides. Each exterior angle is formed by extending one side of the polygon at a vertex. For a regular polygon, each exterior angle can be calculated as: $\text{Exterior angle} = \frac{360^\circ}{N}$ +3. **Diagonals**: A diagonal is a line segment connecting two non-adjacent vertices of a polygon. The number of diagonals (D) in a polygon with N sides can be calculated using the formula: $D = \frac{N(N - 3)}{2}$. For example, a pentagon (5 sides) has 5 diagonals, while a hexagon (6 sides) has 9 diagonals. +4. **Area**: The area of a polygon can be calculated using various methods depending on the type of polygon. For regular polygons, the area can be calculated using the formula: $\text{Area} = \frac{1}{4} N s^2 \cot\left(\frac{\pi}{N}\right)$ where $s$ is the length of a side. For irregular polygons, methods such as triangulation or the shoelace formula can be used. +5. **Perimeter**: The perimeter of a polygon is the total length of its sides. For a polygon with N sides, the perimeter $P$ can be calculated as: $P = s_1 + s_2 + s_3 + ... + s_N$ where $s_1, s_2, ..., s_N$ are the lengths of the sides. +6. **Symmetry**: Regular polygons exhibit a high degree of symmetry. They have multiple lines of symmetry and rotational symmetry. The number of lines of symmetry in a regular polygon is equal to the number of sides $N$. ## Triangulation @@ -373,13 +353,13 @@ The simplest method is to choose one vertex and connect it to all non-adjacent v E - △ABC - △ACD - △ADE + △ABC + △ACD + △ADE - AC - AD + AC + AD @@ -504,15 +484,15 @@ The simplest method is to choose one vertex and connect it to all non-adjacent v F - △ABC - △ACD - △ADE - △AEF + △ABC + △ACD + △ADE + △AEF - AC + AC AD - AE + AE @@ -560,7 +540,7 @@ The simplest method is to choose one vertex and connect it to all non-adjacent v - Note: All triangles share vertex A as a common point + Note: All triangles share vertex A as a common point. This creates a "fan" pattern radiating from A @@ -625,10 +605,10 @@ Both methods create exactly 2 triangles, as predicted by the formula $N-2 = 4-2 △ABC - △ACD + △ACD - AC + AC @@ -676,11 +656,11 @@ Both methods create exactly 2 triangles, as predicted by the formula $N-2 = 4-2 D - △ABD - △BCD + △ABD + △BCD - BD + BD From 35e9302c6e571602772d6117e9da52e82404fc1c Mon Sep 17 00:00:00 2001 From: Aron T Date: Tue, 30 Sep 2025 21:29:13 +0300 Subject: [PATCH 05/10] Add additional formula for n-corner areas --- docs/src/Geometry/03 Polygons.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/src/Geometry/03 Polygons.md b/docs/src/Geometry/03 Polygons.md index 1d96354..8ce9544 100644 --- a/docs/src/Geometry/03 Polygons.md +++ b/docs/src/Geometry/03 Polygons.md @@ -262,7 +262,7 @@ Polygons have several important properties that are useful in geometry: 1. **Sum of Interior Angles**: The sum of the interior angles of a polygon with N sides is given by the formula: $\text{Sum of interior angles} = (N - 2) \times 180^\circ$. For example, a triangle (3 sides) has a sum of interior angles equal to $180^\circ$, while a quadrilateral (4 sides) has a sum of $360^\circ$. 2. **Exterior Angles**: The sum of the exterior angles of any polygon is always $360^\circ$, regardless of the number of sides. Each exterior angle is formed by extending one side of the polygon at a vertex. For a regular polygon, each exterior angle can be calculated as: $\text{Exterior angle} = \frac{360^\circ}{N}$ 3. **Diagonals**: A diagonal is a line segment connecting two non-adjacent vertices of a polygon. The number of diagonals (D) in a polygon with N sides can be calculated using the formula: $D = \frac{N(N - 3)}{2}$. For example, a pentagon (5 sides) has 5 diagonals, while a hexagon (6 sides) has 9 diagonals. -4. **Area**: The area of a polygon can be calculated using various methods depending on the type of polygon. For regular polygons, the area can be calculated using the formula: $\text{Area} = \frac{1}{4} N s^2 \cot\left(\frac{\pi}{N}\right)$ where $s$ is the length of a side. For irregular polygons, methods such as triangulation or the shoelace formula can be used. +4. **Area**: The area of a polygon can be calculated using various methods depending on the type of polygon. For regular polygons, the area can be calculated using the formula: $\text{Area} = \frac{1}{4} N s^2 \cot\left(\frac{\pi}{N}\right)$ where $s$ is the length of a side. If you circumscribe the regular polygon with a circle of radius $r$ (the distance from the center to a vertex), the area can also be expressed as: $\text{Area} = \frac{1}{2} N r^2 \sin\left(\frac{2\pi}{N}\right)$. For irregular polygons, methods such as triangulation or the shoelace formula can be used. 5. **Perimeter**: The perimeter of a polygon is the total length of its sides. For a polygon with N sides, the perimeter $P$ can be calculated as: $P = s_1 + s_2 + s_3 + ... + s_N$ where $s_1, s_2, ..., s_N$ are the lengths of the sides. 6. **Symmetry**: Regular polygons exhibit a high degree of symmetry. They have multiple lines of symmetry and rotational symmetry. The number of lines of symmetry in a regular polygon is equal to the number of sides $N$. @@ -760,3 +760,4 @@ To verify your triangulation is correct: - Using known triangle properties to solve unknown polygon properties The power of triangulation lies in its ability to reduce complex polygonal problems to collections of simple triangle problems, using only the basic geometric tools we've already developed. + From 6d12b041659dbe3a6aaa5ae99e66301b440c78e5 Mon Sep 17 00:00:00 2001 From: Aron T Date: Thu, 2 Oct 2025 13:28:12 +0300 Subject: [PATCH 06/10] Add documentation on cyclic quadrilaterals including diagram --- docs/src/Geometry/03 Polygons.md | 73 ++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/docs/src/Geometry/03 Polygons.md b/docs/src/Geometry/03 Polygons.md index 8ce9544..c11fb68 100644 --- a/docs/src/Geometry/03 Polygons.md +++ b/docs/src/Geometry/03 Polygons.md @@ -761,3 +761,76 @@ To verify your triangulation is correct: The power of triangulation lies in its ability to reduce complex polygonal problems to collections of simple triangle problems, using only the basic geometric tools we've already developed. +## Cyclic Quadrilaterals + +A quadrilateral can be inscribed in a circle ([cyclic quadrilateral](https://mathworld.wolfram.com/CyclicQuadrilateral.html)) if and only if the sum of each pair of opposite angles is $180^\circ$. This property is useful in various geometric proofs and calculations. + +```@raw html + + + + Cyclic Quadrilateral Inscribed in a Circle + + + + + + + + + + + + + + + + + + + + A + B + C + D + + ∠A + ∠B + ∠C + ∠D + + + Property: ∠A + ∠C = 180° and ∠B + ∠D = 180° + + +``` + +### Calculating Area of a Cyclic Quadrilateral + +The area of a cyclic quadrilateral can be calculated using [Brahmagupta's formula](https://mathworld.wolfram.com/BrahmaguptasFormula.html), which is an extension of Heron's formula for triangles. If a cyclic quadrilateral has side lengths $a$, $b$, $c$, and $d$, the area $K$ can be calculated as follows: +$$K = \sqrt{(s-a)(s-b)(s-c)(s-d)}$$ +where $s$ is the semiperimeter: +$$s = \frac{a + b + c + d}{2}$$ +This formula is particularly useful for finding the area when the side lengths are known, without needing to know the angles or the height of the quadrilateral. From e6b79dfd7391d45f0e903575b583ac4f502e9fa2 Mon Sep 17 00:00:00 2001 From: Aron T Date: Thu, 2 Oct 2025 15:26:45 +0300 Subject: [PATCH 07/10] WIP; Examples of area of regular polygons using Julia --- notebooks/Basics.ipynb | 189 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 187 insertions(+), 2 deletions(-) diff --git a/notebooks/Basics.ipynb b/notebooks/Basics.ipynb index 02e18ec..a6774cc 100644 --- a/notebooks/Basics.ipynb +++ b/notebooks/Basics.ipynb @@ -2463,7 +2463,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -3245,7 +3245,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Polygons\n" + "## Polygons" ] }, { @@ -3492,6 +3492,191 @@ "- Height: $\\frac{\\sqrt{6}}{3}$\n", "\n" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### N-Corners" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Regular Polygon Area Calculation\n", + "\n", + "For a regular polygon with N sides and side length s, the area formula is:\n", + "$$F = \\frac{1}{4} N s^2 \\cot\\left(\\frac{\\pi}{N}\\right)$$\n", + "\n", + "Let's calculate this for a polygon with 3600 sides and side length b:" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Calculating area of regular polygon with N = 3600 sides and side length b\n", + "Area Formula = 0.25N*(b^2)*cot(π / N)\n", + "Calculate area with N= 3600 sides = 1.0313237694360806e6(b^2)\n", + "Test for b = 1\n", + "Area for b=1 and N=3600 sides (full): 1.0313237694360806e6\n", + "Area for b=1 and N=3600 sides (10 digits): 1.0313237694360806e6\n", + "Method 2: Format with Printf\n", + "Area for b=1 and N=3600 sides (formatted): 1031323.7694\n", + "Method 3: Printf with Scientific notation and controlled precision\n", + "Area for b=1 and N=3600 sides (scientific): 1.0313237694e+06\n", + "\n", + "For very large N, cot(π/N) ≈ N/π, so the area approaches (N²*b²)/(4π)\n", + "Let's calculate the numerical approximation\n", + "Numerical approximation of area for b=1 and N=3600 sides: 1.0313240312e6\n", + "This approximation should be close to the exact symbolic calculation.\n", + "\n", + "--- Circle Comparison as N → ∞ ---\n", + "For a circle with circumference C = N*b, radius r = C/(2π) = N*b/(2π)\n", + "Circle area = π*r² = π*(N*b/(2π))² = (N²*b²)/(4π)\n", + "Circle coefficient for N=3600: N²/(4π) = 1.0313240312e6\n", + "Circle area for b=1 and N=3600: 1.0313240312e6\n", + "Difference (polygon - circle): -0.2617994\n", + "Relative error: 2.538479e-07\n" + ] + } + ], + "source": [ + "@variables b\n", + "println(\"Calculating area of regular polygon with N = 3600 sides and side length b\")\n", + "@variables b, N\n", + "# Area formula: A = (1/4) * N * s^2 * cot(π/N)\n", + "area_formula = (1/4) * N * b^2 * cot(π/N)\n", + "println(\"Area Formula = \", area_formula)\n", + "\n", + "# Simplify the expression\n", + "area_simplified = substitute(area_formula, N=>3600)\n", + "println(\"Calculate area with N= 3600 sides = \", area_simplified)\n", + "\n", + "# test for value of b - with controlled precision\n", + "println(\"Test for b = 1\")\n", + "area_test = substitute(area_simplified, b=>1)\n", + "println(\"Area for b=1 and N=3600 sides (full): \", area_test)\n", + "\n", + "# Method 1: Use Symbolics.value() to extract numerical value, then round\n", + "using Printf\n", + "area_numerical_value = Symbolics.value(area_test)\n", + "area_rounded = round(area_numerical_value, digits=10)\n", + "println(\"Area for b=1 and N=3600 sides (10 digits): \", area_rounded)\n", + "println(\"Method 2: Format with Printf\")\n", + "@printf(\"Area for b=1 and N=3600 sides (formatted): %.4f\\n\", area_numerical_value)\n", + "println(\"Method 3: Printf with Scientific notation and controlled precision\")\n", + "@printf(\"Area for b=1 and N=3600 sides (scientific): %.10e\\n\", area_numerical_value)\n", + "\n", + "# Numerical approximation for large N\n", + "println(\"\\nFor very large N, cot(π/N) ≈ N/π, so the area approaches (N²*b²)/(4π)\")\n", + "println(\"Let's calculate the numerical approximation\")\n", + "N_large = 3600\n", + "b_value = 1\n", + "area_approx = (N_large^2 * b_value^2) / (4 * π)\n", + "println(\"Numerical approximation of area for b=1 and N=3600 sides: \", round(area_approx, digits=4))\n", + "println(\"This approximation should be close to the exact symbolic calculation.\") \n", + "\n", + "# Compare with circle: as N → ∞, this approaches the area of a circle\n", + "println(\"\\n--- Circle Comparison as N → ∞ ---\")\n", + "println(\"For a circle with circumference C = N*b, radius r = C/(2π) = N*b/(2π)\")\n", + "println(\"Circle area = π*r² = π*(N*b/(2π))² = (N²*b²)/(4π)\")\n", + "\n", + "# Calculate circle coefficient symbolically\n", + "@variables N_sym\n", + "circle_coefficient_symbolic = N_sym^2 / (4*π)\n", + "circle_coefficient_3600 = substitute(circle_coefficient_symbolic, N_sym=>3600)\n", + "circle_area_3600 = Symbolics.value(circle_coefficient_3600) * b_value^2\n", + "\n", + "println(\"Circle coefficient for N=3600: N²/(4π) = \", round(Symbolics.value(circle_coefficient_3600), digits=4))\n", + "println(\"Circle area for b=1 and N=3600: \", round(circle_area_3600, digits=4))\n", + "\n", + "# Show the difference between polygon and circle\n", + "difference = area_numerical_value - circle_area_3600\n", + "println(\"Difference (polygon - circle): \", round(difference, digits=8))\n", + "@printf(\"Relative error: %.6e\\n\", abs(difference)/circle_area_3600)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A regular polygon can be divided into N triangles from the center. We can use the geometric charasterics of these triangle listed below, to calculate the area using triangulation. \n", + "\n", + "The important characteristics for a regular $N$-gon with side length $b$:\n", + "\n", + "- Central angle = $\\frac{2\\pi}{N}$\n", + "- Each triangle has base = $b$ and two equal sides (radii) = $r$\n", + "- The apothem (height of triangle) = $r \\cdot \\cos\\left(\\frac{\\pi}{N}\\right)$\n", + "- Area of one triangle = $\\frac{1}{2} \\cdot \\text{base} \\cdot \\text{height} = \\frac{1}{2} \\cdot b \\cdot \\text{apothem}$\n", + "- Total area = $N \\cdot \\text{triangle\\_area}$\n", + "\n", + "These also support an alternative area formula using the radius $r$:\n", + "$$F = \\frac{1}{2} N r^2 \\sin\\left(\\frac{2\\pi}{N}\\right)$$" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Verification using triangle method:\n", + "A regular polygon with N sides can be divided into N isosceles triangles\n", + "Circumradius r = b/(2*sin(π/N)) = 572.9578678528818b\n", + "Apothem = r * cos(π/N) = 572.9576496867114b\n", + "Area of one triangle = (1/2) * b * apothem = 286.4788248433557(b^2)\n", + "Total area = N * triangle_area = 1.0313237694360806e6(b^2)\n", + "This should equal our original formula: (-1.0313237694360806e6(b^2) + 0.25N*(b^2)*cot(π / N)) == 0\n", + "-1.0313237694360806e6(b^2) + 0.25N*(b^2)*cot(π / N)) == 0\n" + ] + } + ], + "source": [ + "println(\"\\nVerification using triangle method:\")\n", + "println(\"A regular polygon with N sides can be divided into N isosceles triangles\")\n", + "\n", + "N = 3600\n", + "\n", + "\n", + "# First find the radius r from the side length b\n", + "# In a regular N-gon: b = 2*r*sin(π/N), so r = b/(2*sin(π/N))\n", + "r = b / (2 * sin(π/N))\n", + "println(\"Circumradius r = b/(2*sin(π/N)) = \", r)\n", + "\n", + "# Apothem = r * cos(π/N) = [b/(2*sin(π/N))] * cos(π/N) = (b/2) * cot(π/N)\n", + "apothem = r * cos(π/N)\n", + "apothem_simplified = simplify(apothem)\n", + "println(\"Apothem = r * cos(π/N) = \", apothem_simplified)\n", + "\n", + "# Area of one triangle = (1/2) * base * height = (1/2) * b * apothem\n", + "triangle_area = (1/2) * b * apothem_simplified\n", + "triangle_area_simplified = simplify(triangle_area)\n", + "println(\"Area of one triangle = (1/2) * b * apothem = \", triangle_area_simplified)\n", + "\n", + "# Total area = N * triangle_area\n", + "total_area = N * triangle_area_simplified\n", + "total_area_simplified = simplify(total_area)\n", + "println(\"Total area = N * triangle_area = \", total_area_simplified)\n", + "\n", + "# Verify this matches our formula\n", + "println(\"This should equal our original formula: \", simplify(area_formula - total_area_simplified) == 0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] } ], "metadata": { From 3896a138a4d5586f4ee5f41700daec0050844f39 Mon Sep 17 00:00:00 2001 From: Aron T Date: Fri, 3 Oct 2025 17:19:15 +0300 Subject: [PATCH 08/10] Fix calculation on regular polygon: - split cell - improve precision handling - add quantitative comparison with absolute and relative error --- notebooks/Basics.ipynb | 120 +++++++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 41 deletions(-) diff --git a/notebooks/Basics.ipynb b/notebooks/Basics.ipynb index a6774cc..b63edff 100644 --- a/notebooks/Basics.ipynb +++ b/notebooks/Basics.ipynb @@ -2463,7 +2463,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -3504,8 +3504,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Regular Polygon Area Calculation\n", - "\n", + "#### Regular Polygon Area Calculation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "For a regular polygon with N sides and side length s, the area formula is:\n", "$$F = \\frac{1}{4} N s^2 \\cot\\left(\\frac{\\pi}{N}\\right)$$\n", "\n", @@ -3514,7 +3519,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -3523,27 +3528,16 @@ "text": [ "Calculating area of regular polygon with N = 3600 sides and side length b\n", "Area Formula = 0.25N*(b^2)*cot(π / N)\n", - "Calculate area with N= 3600 sides = 1.0313237694360806e6(b^2)\n", - "Test for b = 1\n", - "Area for b=1 and N=3600 sides (full): 1.0313237694360806e6\n", - "Area for b=1 and N=3600 sides (10 digits): 1.0313237694360806e6\n", + "Using substitute, calculate symbolic area with N= 3600 sides = 1.0313237694360806e6(b^2)\n", + "Area for b=1 and N=3600 sides (full substitution): 1.0313237694360806e6\n", + "\n", + "--- Test for value of b - with controlled precision ---\n", + "Method 1: Use Symbolics.value() to extract numerical value, then round\n", + "Area for b=1 and N=3600 sides (4 digits after decimal): 1.0313237694e6\n", "Method 2: Format with Printf\n", "Area for b=1 and N=3600 sides (formatted): 1031323.7694\n", "Method 3: Printf with Scientific notation and controlled precision\n", - "Area for b=1 and N=3600 sides (scientific): 1.0313237694e+06\n", - "\n", - "For very large N, cot(π/N) ≈ N/π, so the area approaches (N²*b²)/(4π)\n", - "Let's calculate the numerical approximation\n", - "Numerical approximation of area for b=1 and N=3600 sides: 1.0313240312e6\n", - "This approximation should be close to the exact symbolic calculation.\n", - "\n", - "--- Circle Comparison as N → ∞ ---\n", - "For a circle with circumference C = N*b, radius r = C/(2π) = N*b/(2π)\n", - "Circle area = π*r² = π*(N*b/(2π))² = (N²*b²)/(4π)\n", - "Circle coefficient for N=3600: N²/(4π) = 1.0313240312e6\n", - "Circle area for b=1 and N=3600: 1.0313240312e6\n", - "Difference (polygon - circle): -0.2617994\n", - "Relative error: 2.538479e-07\n" + "Area for b=1 and N=3600 sides (scientific): 1.0313237694e+06\n" ] } ], @@ -3554,37 +3548,81 @@ "# Area formula: A = (1/4) * N * s^2 * cot(π/N)\n", "area_formula = (1/4) * N * b^2 * cot(π/N)\n", "println(\"Area Formula = \", area_formula)\n", - "\n", "# Simplify the expression\n", - "area_simplified = substitute(area_formula, N=>3600)\n", - "println(\"Calculate area with N= 3600 sides = \", area_simplified)\n", - "\n", - "# test for value of b - with controlled precision\n", - "println(\"Test for b = 1\")\n", - "area_test = substitute(area_simplified, b=>1)\n", - "println(\"Area for b=1 and N=3600 sides (full): \", area_test)\n", + "area_symbolic = substitute(area_formula, N=>3600)\n", + "println(\"Using substitute, calculate symbolic area with N= 3600 sides = \", area_symbolic)\n", + "area_test = substitute(area_symbolic, b=>1)\n", + "println(\"Area for b=1 and N=3600 sides (full substitution): \", area_test)\n", "\n", - "# Method 1: Use Symbolics.value() to extract numerical value, then round\n", - "using Printf\n", + "println(\"\")\n", + "println(\"--- Test for value of b - with controlled precision ---\")\n", + "println(\"Method 1: Use Symbolics.value() to extract numerical value, then round\")\n", "area_numerical_value = Symbolics.value(area_test)\n", - "area_rounded = round(area_numerical_value, digits=10)\n", - "println(\"Area for b=1 and N=3600 sides (10 digits): \", area_rounded)\n", + "area_rounded = round(area_numerical_value, digits=4)\n", + "println(\"Area for b=1 and N=3600 sides (4 digits after decimal): \", area_rounded)\n", "println(\"Method 2: Format with Printf\")\n", "@printf(\"Area for b=1 and N=3600 sides (formatted): %.4f\\n\", area_numerical_value)\n", "println(\"Method 3: Printf with Scientific notation and controlled precision\")\n", - "@printf(\"Area for b=1 and N=3600 sides (scientific): %.10e\\n\", area_numerical_value)\n", - "\n", - "# Numerical approximation for large N\n", - "println(\"\\nFor very large N, cot(π/N) ≈ N/π, so the area approaches (N²*b²)/(4π)\")\n", + "@printf(\"Area for b=1 and N=3600 sides (scientific): %.10e\\n\", area_numerical_value)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "--- Numerical approximation for large N ---\n", + "For very large N, cot(π/N) ≈ N/π, so the area approaches (N²*b²)/(4π)\n", + "Let's calculate the numerical approximation\n", + "Numerical approximation of area for b=1 and N=3600 sides: 1.0313240312354818e6\n", + "This approximation should be close to the exact symbolic calculation.\n", + "Difference: 0.2618 (0.000025% relative error)\n", + "Excellent agreement!\n", + "\n", + "--- Circle Comparison as N → ∞ ---\n", + "As N → ∞, this approaches the area of a circle\n", + "For a circle with circumference C = N*b, radius r = C/(2π) = N*b/(2π)\n", + "Circle area = π*r² = π*(N*b/(2π))² = (N²*b²)/(4π)\n", + "Circle coefficient for N=3600: N²/(4π) = 1.0313240312e6\n", + "Circle area for b=1 and N=3600: 1.0313240312e6\n", + "Difference (polygon - circle): -0.2617994\n", + "Relative error: 2.538479e-07\n", + "Excellent agreement!\n", + "\n", + "--- Circle Comparison as N → ∞ ---\n", + "As N → ∞, this approaches the area of a circle\n", + "For a circle with circumference C = N*b, radius r = C/(2π) = N*b/(2π)\n", + "Circle area = π*r² = π*(N*b/(2π))² = (N²*b²)/(4π)\n", + "Circle coefficient for N=3600: N²/(4π) = 1.0313240312e6\n", + "Circle area for b=1 and N=3600: 1.0313240312e6\n", + "Difference (polygon - circle): -0.2617994\n", + "Relative error: 2.538479e-07\n" + ] + } + ], + "source": [ + "println(\"\\n--- Numerical approximation for large N ---\")\n", + "println(\"For very large N, cot(π/N) ≈ N/π, so the area approaches (N²*b²)/(4π)\")\n", "println(\"Let's calculate the numerical approximation\")\n", "N_large = 3600\n", "b_value = 1\n", "area_approx = (N_large^2 * b_value^2) / (4 * π)\n", - "println(\"Numerical approximation of area for b=1 and N=3600 sides: \", round(area_approx, digits=4))\n", - "println(\"This approximation should be close to the exact symbolic calculation.\") \n", + "println(\"Numerical approximation of area for b=1 and N=3600 sides: \", area_approx)\n", + "println(\"This approximation should be close to the exact symbolic calculation.\")\n", + "\n", + "# Quantitative comparison with absolute and relative error\n", + "diff_value = abs(area_numerical_value - area_approx)\n", + "rel_error = diff_value / area_approx\n", + "@printf(\"Difference: %.4f (%.6f%% relative error)\\n\", diff_value, rel_error * 100)\n", + "println(rel_error < 1e-5 ? \"Excellent agreement!\" : \"Values differ\")\n", "\n", - "# Compare with circle: as N → ∞, this approaches the area of a circle\n", "println(\"\\n--- Circle Comparison as N → ∞ ---\")\n", + "println(\"As N → ∞, this approaches the area of a circle\")\n", "println(\"For a circle with circumference C = N*b, radius r = C/(2π) = N*b/(2π)\")\n", "println(\"Circle area = π*r² = π*(N*b/(2π))² = (N²*b²)/(4π)\")\n", "\n", From 01f9731a355a2328894f2c7a4e88019a2f90731b Mon Sep 17 00:00:00 2001 From: Aron T Date: Sun, 5 Oct 2025 17:02:49 +0300 Subject: [PATCH 09/10] Fix presntation of numerical approximation results --- notebooks/Basics.ipynb | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/notebooks/Basics.ipynb b/notebooks/Basics.ipynb index b63edff..7b3432d 100644 --- a/notebooks/Basics.ipynb +++ b/notebooks/Basics.ipynb @@ -3519,7 +3519,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -3537,6 +3537,8 @@ "Method 2: Format with Printf\n", "Area for b=1 and N=3600 sides (formatted): 1031323.7694\n", "Method 3: Printf with Scientific notation and controlled precision\n", + "Area for b=1 and N=3600 sides (scientific): 1.0313237694e+06\n", + "\n", "Area for b=1 and N=3600 sides (scientific): 1.0313237694e+06\n" ] } @@ -3553,7 +3555,7 @@ "println(\"Using substitute, calculate symbolic area with N= 3600 sides = \", area_symbolic)\n", "area_test = substitute(area_symbolic, b=>1)\n", "println(\"Area for b=1 and N=3600 sides (full substitution): \", area_test)\n", - "\n", + "using Printf\n", "println(\"\")\n", "println(\"--- Test for value of b - with controlled precision ---\")\n", "println(\"Method 1: Use Symbolics.value() to extract numerical value, then round\")\n", @@ -3568,7 +3570,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -3585,23 +3587,15 @@ "Excellent agreement!\n", "\n", "--- Circle Comparison as N → ∞ ---\n", + "What follows is an alternative presentation of the same result using the circle area formula\n", "As N → ∞, this approaches the area of a circle\n", "For a circle with circumference C = N*b, radius r = C/(2π) = N*b/(2π)\n", - "Circle area = π*r² = π*(N*b/(2π))² = (N²*b²)/(4π)\n", + "Circle area = π*r² = π*(N*b/(2π))² = (N²*b²)/(4π) which is same as previous approximation\n", "Circle coefficient for N=3600: N²/(4π) = 1.0313240312e6\n", "Circle area for b=1 and N=3600: 1.0313240312e6\n", "Difference (polygon - circle): -0.2617994\n", - "Relative error: 2.538479e-07\n", - "Excellent agreement!\n", - "\n", - "--- Circle Comparison as N → ∞ ---\n", - "As N → ∞, this approaches the area of a circle\n", - "For a circle with circumference C = N*b, radius r = C/(2π) = N*b/(2π)\n", - "Circle area = π*r² = π*(N*b/(2π))² = (N²*b²)/(4π)\n", - "Circle coefficient for N=3600: N²/(4π) = 1.0313240312e6\n", - "Circle area for b=1 and N=3600: 1.0313240312e6\n", - "Difference (polygon - circle): -0.2617994\n", - "Relative error: 2.538479e-07\n" + "Difference: 0.2618 (0.000025% relative error)\n", + "Excellent agreement!\n" ] } ], @@ -3622,9 +3616,10 @@ "println(rel_error < 1e-5 ? \"Excellent agreement!\" : \"Values differ\")\n", "\n", "println(\"\\n--- Circle Comparison as N → ∞ ---\")\n", + "println(\"What follows is an alternative presentation of the same result using the circle area formula\")\n", "println(\"As N → ∞, this approaches the area of a circle\")\n", "println(\"For a circle with circumference C = N*b, radius r = C/(2π) = N*b/(2π)\")\n", - "println(\"Circle area = π*r² = π*(N*b/(2π))² = (N²*b²)/(4π)\")\n", + "println(\"Circle area = π*r² = π*(N*b/(2π))² = (N²*b²)/(4π) which is same as previous approximation\")\n", "\n", "# Calculate circle coefficient symbolically\n", "@variables N_sym\n", @@ -3638,14 +3633,16 @@ "# Show the difference between polygon and circle\n", "difference = area_numerical_value - circle_area_3600\n", "println(\"Difference (polygon - circle): \", round(difference, digits=8))\n", - "@printf(\"Relative error: %.6e\\n\", abs(difference)/circle_area_3600)" + "rel_error = abs(difference)/circle_area_3600\n", + "@printf(\"Difference: %.4f (%.6f%% relative error)\\n\", diff_value, rel_error * 100)\n", + "println(rel_error < 1e-5 ? \"Excellent agreement!\" : \"Values differ\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "A regular polygon can be divided into N triangles from the center. We can use the geometric charasterics of these triangle listed below, to calculate the area using triangulation. \n", + "A regular polygon can be divided into N triangles from the center. We can use the geometric characteristics of these triangle listed below, to calculate the area using triangulation.\n", "\n", "The important characteristics for a regular $N$-gon with side length $b$:\n", "\n", From 1575af3367fc7bc7496f1d25e08cece50676b715 Mon Sep 17 00:00:00 2001 From: Aron T Date: Mon, 6 Oct 2025 15:06:29 +0300 Subject: [PATCH 10/10] Various ways to calculate including triangulation and formula using radius --- notebooks/Basics.ipynb | 143 +++++++++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 50 deletions(-) diff --git a/notebooks/Basics.ipynb b/notebooks/Basics.ipynb index 7b3432d..a565b3a 100644 --- a/notebooks/Basics.ipynb +++ b/notebooks/Basics.ipynb @@ -2463,7 +2463,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ @@ -3519,7 +3519,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -3537,8 +3537,6 @@ "Method 2: Format with Printf\n", "Area for b=1 and N=3600 sides (formatted): 1031323.7694\n", "Method 3: Printf with Scientific notation and controlled precision\n", - "Area for b=1 and N=3600 sides (scientific): 1.0313237694e+06\n", - "\n", "Area for b=1 and N=3600 sides (scientific): 1.0313237694e+06\n" ] } @@ -3570,7 +3568,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 32, "metadata": {}, "outputs": [ { @@ -3593,8 +3591,8 @@ "Circle area = π*r² = π*(N*b/(2π))² = (N²*b²)/(4π) which is same as previous approximation\n", "Circle coefficient for N=3600: N²/(4π) = 1.0313240312e6\n", "Circle area for b=1 and N=3600: 1.0313240312e6\n", - "Difference (polygon - circle): -0.2617994\n", - "Difference: 0.2618 (0.000025% relative error)\n", + "Difference (polygon - circle): -0.261799401254\n", + "Difference: -0.2618 (0.00002538% relative error)\n", "Excellent agreement!\n" ] } @@ -3631,10 +3629,10 @@ "println(\"Circle area for b=1 and N=3600: \", round(circle_area_3600, digits=4))\n", "\n", "# Show the difference between polygon and circle\n", - "difference = area_numerical_value - circle_area_3600\n", - "println(\"Difference (polygon - circle): \", round(difference, digits=8))\n", - "rel_error = abs(difference)/circle_area_3600\n", - "@printf(\"Difference: %.4f (%.6f%% relative error)\\n\", diff_value, rel_error * 100)\n", + "diff_value = area_numerical_value - circle_area_3600\n", + "println(\"Difference (polygon - circle): \", round(diff_value, digits=12))\n", + "rel_error = abs(diff_value)/circle_area_3600\n", + "@printf(\"Difference: %.4f (%.8f%% relative error)\\n\", diff_value, rel_error * 100)\n", "println(rel_error < 1e-5 ? \"Excellent agreement!\" : \"Values differ\")" ] }, @@ -3650,15 +3648,12 @@ "- Each triangle has base = $b$ and two equal sides (radii) = $r$\n", "- The apothem (height of triangle) = $r \\cdot \\cos\\left(\\frac{\\pi}{N}\\right)$\n", "- Area of one triangle = $\\frac{1}{2} \\cdot \\text{base} \\cdot \\text{height} = \\frac{1}{2} \\cdot b \\cdot \\text{apothem}$\n", - "- Total area = $N \\cdot \\text{triangle\\_area}$\n", - "\n", - "These also support an alternative area formula using the radius $r$:\n", - "$$F = \\frac{1}{2} N r^2 \\sin\\left(\\frac{2\\pi}{N}\\right)$$" + "- Total area = $N \\cdot \\text{triangle\\_area}$\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, "outputs": [ { @@ -3666,52 +3661,100 @@ "output_type": "stream", "text": [ "\n", - "Verification using triangle method:\n", + "Find the area using trianglulation method:\n", "A regular polygon with N sides can be divided into N isosceles triangles\n", - "Circumradius r = b/(2*sin(π/N)) = 572.9578678528818b\n", - "Apothem = r * cos(π/N) = 572.9576496867114b\n", - "Area of one triangle = (1/2) * b * apothem = 286.4788248433557(b^2)\n", - "Total area = N * triangle_area = 1.0313237694360806e6(b^2)\n", - "This should equal our original formula: (-1.0313237694360806e6(b^2) + 0.25N*(b^2)*cot(π / N)) == 0\n", - "-1.0313237694360806e6(b^2) + 0.25N*(b^2)*cot(π / N)) == 0\n" + "First find the radius r from the side length b\n", + "In a regular N-gon: b = 2*r*sin(π/N), so r = b / (2sin(π / N))\n", + "lets calculate r with b = 1 and N = 3600\n", + "Circumradius r = b/(2*sin(π/N)) = 572.9578678528818\n", + "Now calculate the apothem (height) of one triangle\n", + "Apothem = r * cos(π/N) = [b/(2*sin(π/N))] * cos(π/N) = (1//2)*b*cot(π / N)\n", + "Apothem for b=1 and N=3600 = 572.9576496867114\n", + "Now calculate the area of one triangle\n", + "Area of one triangle = (1/2) * base * height = (1/2) * b * apothem = 286.4788248433557\n", + "Total area = N * triangle_area = 1.0313237694360806e6\n", + "Difference (previous - current): 0.0\n", + "Difference: 0.0000 (0.00000000% relative error)\n", + "Excellent agreement!\n", + "2sin(π / N))\n", + "lets calculate r with b = 1 and N = 3600\n", + "Circumradius r = b/(2*sin(π/N)) = 572.9578678528818\n", + "Now calculate the apothem (height) of one triangle\n", + "Apothem = r * cos(π/N) = [b/(2*sin(π/N))] * cos(π/N) = (1//2)*b*cot(π / N)\n", + "Apothem for b=1 and N=3600 = 572.9576496867114\n", + "Now calculate the area of one triangle\n", + "Area of one triangle = (1/2) * base * height = (1/2) * b * apothem = 286.4788248433557\n", + "Total area = N * triangle_area = 1.0313237694360806e6\n", + "Difference (previous - current): 0.0\n", + "Difference: 0.0000 (0.00000000% relative error)\n", + "Excellent agreement!\n" ] } ], "source": [ - "println(\"\\nVerification using triangle method:\")\n", + "println(\"\\nFind the area using trianglulation method:\")\n", "println(\"A regular polygon with N sides can be divided into N isosceles triangles\")\n", - "\n", - "N = 3600\n", - "\n", - "\n", - "# First find the radius r from the side length b\n", - "# In a regular N-gon: b = 2*r*sin(π/N), so r = b/(2*sin(π/N))\n", - "r = b / (2 * sin(π/N))\n", + "println(\"First find the radius r from the side length b\")\n", + "@variables b N\n", + "r_symbolic = b / (2 * sin(π/N))\n", + "println(\"In a regular N-gon: b = 2*r*sin(π/N), so r = \", r_symbolic)\n", + "println(\"lets calculate r with b = 1 and N = 3600\")\n", + "r_substitute = substitute(r_symbolic, Dict(b=>1, N=>3600))\n", + "r = Symbolics.value(r_substitute)\n", "println(\"Circumradius r = b/(2*sin(π/N)) = \", r)\n", - "\n", - "# Apothem = r * cos(π/N) = [b/(2*sin(π/N))] * cos(π/N) = (b/2) * cot(π/N)\n", - "apothem = r * cos(π/N)\n", - "apothem_simplified = simplify(apothem)\n", - "println(\"Apothem = r * cos(π/N) = \", apothem_simplified)\n", - "\n", - "# Area of one triangle = (1/2) * base * height = (1/2) * b * apothem\n", - "triangle_area = (1/2) * b * apothem_simplified\n", - "triangle_area_simplified = simplify(triangle_area)\n", - "println(\"Area of one triangle = (1/2) * b * apothem = \", triangle_area_simplified)\n", - "\n", - "# Total area = N * triangle_area\n", - "total_area = N * triangle_area_simplified\n", - "total_area_simplified = simplify(total_area)\n", - "println(\"Total area = N * triangle_area = \", total_area_simplified)\n", - "\n", - "# Verify this matches our formula\n", - "println(\"This should equal our original formula: \", simplify(area_formula - total_area_simplified) == 0)" + "println(\"Now calculate the apothem (height) of one triangle\")\n", + "apothem_symbolic = (b/2) * cot(π/N)\n", + "println(\"Apothem = r * cos(π/N) = [b/(2*sin(π/N))] * cos(π/N) = \", apothem_symbolic)\n", + "apothem_substitute = substitute(apothem_symbolic, Dict(b=>1, N=>3600))\n", + "apothem = Symbolics.value(apothem_substitute)\n", + "println(\"Apothem for b=1 and N=3600 = \", apothem)\n", + "println(\"Now calculate the area of one triangle\")\n", + "triangle_area = (1/2) * 1 * apothem\n", + "println(\"Area of one triangle = (1/2) * base * height = (1/2) * b * apothem = \", triangle_area)\n", + "total_area = 3600 * triangle_area\n", + "println(\"Total area = N * triangle_area = \", total_area)\n", + "# Show the difference between polygon and circle\n", + "diff_value = area_numerical_value - total_area\n", + "println(\"Difference (previous - current): \", round(diff_value, digits=12))\n", + "rel_error = abs(diff_value)/total_area\n", + "@printf(\"Difference: %.4f (%.8f%% relative error)\\n\", diff_value, rel_error * 100)\n", + "println(rel_error < 1e-5 ? \"Excellent agreement!\" : \"Values differ\")" ] }, { "cell_type": "markdown", "metadata": {}, - "source": [] + "source": [ + "Finally we can calculate the area of the polygon using the above characteristics and the formula:\n", + "$$F = \\frac{1}{2} N r^2 \\sin\\left(\\frac{2\\pi}{N}\\right)$$" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Area using another formula F = 1/2 * N * r^2 * sin(2π/N) = 1.0313237694360806e6\n", + "Difference (previous - current): 0.0\n", + "Difference: 0.0000 (0.00000000% relative error)\n", + "Excellent agreement!\n" + ] + } + ], + "source": [ + "F = 1/2 * 3600 * r^2 * sind(360/3600)\n", + "println(\"Area using another formula F = 1/2 * N * r^2 * sin(2π/N) = \", F)\n", + "# Show the difference between polygon and circle\n", + "diff_value = area_numerical_value - F\n", + "println(\"Difference (previous - current): \", round(diff_value, digits=12))\n", + "rel_error = abs(diff_value)/F\n", + "@printf(\"Difference: %.4f (%.8f%% relative error)\\n\", diff_value, rel_error * 100)\n", + "println(rel_error < 1e-5 ? \"Excellent agreement!\" : \"Values differ\")" + ] } ], "metadata": {