Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔪 Coding the Perfect Cut

SigmaCamp 2026 Workshop | NEMPA - UFBA

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 Challenge

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.

  1. Manual Mode: The user tries to find the perfect cut by adjusting the angle and position sliders.
  2. Algorithm Mode: The machine solves the problem using Binary Search, demonstrating the power of logarithmic complexity ($O(\log n)$).
  3. Chaos Mode: Replaces the simple brownie (5 vertices) with a randomly generated polygon containing 300+ vertices.
  4. 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.

🧠 Mathematical Concepts

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.

💻 Tech Stack

  • Language: Python 3.10+
  • Framework: Streamlit
  • Geometry Engine: Shapely
  • Visualization: Matplotlib

🚀 How to Run Locally

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-cut

2. Create a virtual environment:

python -m venv venv
source venv/bin/activate  # On Windows use: venv\Scripts\activate

3. Install dependencies:

pip install -r requirements.txt

Run the app:

streamlit run app.py

📚 Learning Resources

To deepen your understanding of the concepts behind this project, we recommend exploring the following resources:

Mathematical Foundations

Python

Computational Geometry

  • 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

Web Development with Streamlit

👥 The Team (NEMPA – UFBA)

Project Lead

Lead Developer

Development Team


© 2026 NEMPA – Núcleo de Estudos em Matemática Pura e Aplicada.
All rights reserved.

About

Source code for the "Coding the Perfect Cut" workshop. This project visualizes the Intermediate Value Theorem applied to 2D geometry, implementing Binary Search for area bisection using Shapely and Streamlit.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages