🇺🇸 English | 🇧🇷 Português
Coding the Perfect Cut is an interactive web application designed to demonstrate concepts of Algebraic Topology and Algorithm Complexity through a gamified geometric challenge.
This tool was developed by the Center for Studies in Pure and Applied Mathematics (NEMPA) at the Federal University of Bahia (UFBA) for the SigmaCamp 2026 International STEM Workshop.
🔗 Live Demo: sigma-perfect-cut.streamlit.app
The goal is simple yet mathematically profound: Divide an irregular polygon (a "brownie") into two equal areas using a single straight cut.
Users face a duel: Human Intuition vs. Machine Precision.
- Manual Mode: The user tries to find the perfect cut by adjusting the angle and position sliders.
- Algorithm Mode: The machine solves the problem using Binary Search, demonstrating the power of logarithmic complexity ($O(\log n)$).
- Chaos Mode: Replaces the simple brownie (5 vertices) with a randomly generated polygon containing 300+ vertices.
- AI Auto-Lock: A dynamic assist mode where the machine continuously calculates the perfect cut position in real-time as you rotate the knife, visualizing the geometric locus of the solution.
The project visualizes the Intermediate Value Theorem (IVT) applied to 2D geometry (often related to the Pancake Theorem).
- Continuity: As the knife moves across the shape, the area to the left changes continuously from 0% to 100%.
- Topology: Therefore, there must be a position where the area is exactly 50%.
- Symmetry: By rotating the angle, we explore the solution space (Cylindrical Topology) to find the cut where the error is zero.
1. Clone the repository:
git clone [https://github.com/NEMPA-UFBA/sigma-perfect-cut.git](https://github.com/NEMPA-UFBA/sigma-perfect-cut.git)
cd sigma-perfect-cut2. Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate3. Install dependencies:
pip install -r requirements.txtRun the app:
streamlit run app.pyTo deepen your understanding of the concepts behind this project, we recommend exploring the following resources:
- Intermediate Value Theorem (IVT): Khan Academy - IVT Introduction
- Topology Basics: 3Blue1Brown - Topology Fundamental Concepts
- Python Course: Curso em Vídeo - YouTube Course
- Documentation: Python Documentation
- W3 Schools: W3 Schools Tutorial
- Shapely Library: Official Shapely Documentation
- Polygon Operations: Learn about intersection, union, and area calculations
- 2D Geometry Algorithms: Study ray casting, line segment intersection, and spatial partitioning
- Streamlit Official Docs: streamlit.io
- Interactive Visualization: Streamlit Components and Plotting Guide
Project Lead
Lead Developer
Development Team
© 2026 NEMPA – Núcleo de Estudos em Matemática Pura e Aplicada.
All rights reserved.