Skip to content

About

A Python-based spatial geometry calculator using SymPy to compute exact areas and volumes with symbolic variables like π and square roots.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

🧊 Spatial Geometry Calculator

CI Python PyQt6 Streamlit SymPy Matplotlib License

A dual-interface (PyQt6 Desktop + Streamlit/Plotly Web) application and Python package engineered to compute areas, perimeters, slant heights, and volumes of 3D geometric solids with exact symbolic precision. Unlike standard calculators that coerce irrationals into floating-point decimals early, Spatial Geometry Calculator preserves exact symbolic expressions ($\pi$, $\sqrt{3}$, $\sqrt{5}$, and rational fractions like $\frac{500\pi}{3}$) alongside side-by-side decimal approximations and real-time 3D rendering.

Spatial Geometry 3D Showcase


🌟 The Competitive Edge

The Problem: Most geometry scripts and calculators convert user inputs and irrational constants into IEEE-754 floating-point numbers immediately, losing mathematical precision and making results unusable for formal proofs, engineering derivations, or academic exams.

The Solution:

  1. Pure Rational & Symbolic Pipeline: Powered by SymPy, user inputs (including decimals and fractions like 2.5 or 1/3) are parsed into exact sympy.Rational objects before evaluation. Square roots ($\sqrt{h^2 + r^2}$) and constants ($\pi, \sqrt{3}$) remain exact throughout the calculation chain.
  2. Dual Symbolic + Decimal Output: Every metric displays its simplified symbolic form (500·π/3), the governing mathematical formula, and its numerical evaluation (≈ 523.5988) simultaneously.
  3. True-to-Scale 3D Geometry: Both the PyQt6/Matplotlib desktop canvas and the Streamlit/Plotly web app construct exact polygon vertices from the base apothem (inradius) or rectangle dimensions ($l \times w$), complete with closed base caps, 1:1:1 aspect ratio, and 3D dimension callout vectors ($r_1, r_2, h, s$).

🚀 Key Features

  • 6 Solid Families $\times$ 5 Base Cross-Sections:
    • Solids: Sphere, Cone, Cylinder, Pyramid, Prism, and Frustum (truncated cone/pyramid).
    • Bases: Square, Rectangle ($l \times w$), Equilateral Triangle, Regular Hexagon, and Circle.
  • Exact Symbolic Computation & Constant Toggles: Maintain $\pi$ and $\sqrt{3}$ symbolically or override them with custom numeric approximations at the click of a checkbox.
  • Dual-Slant Rectangular Pyramids & Homothetic Frustums: Accurately computes distinct lateral slant heights ($s_l, s_w$) for non-square rectangular pyramids and frustums.
  • Two Native Interfaces + Python API:
    • Desktop App (geometry.py): Native dark-themed PyQt6 interface with embedded 3D Matplotlib rendering.
    • Web App (app.py): Interactive Streamlit + Plotly 3D web dashboard with expandable $\LaTeX$ equation blocks.
    • Python Package (spatial_geometry): Clean, zero-GUI symbolic calculation engine ready for scripts, notebooks, or automated grading.

📐 Mathematical Reference

Base Cross-Section Geometry (from Apothem $r$ or Length $l$, Width $w$)

Base Shape Side Length ($a$) Base Area ($A_B$) Perimeter ($P$) 3D Circumradius ($R$)
Circle $2r$ (diameter) $\pi r^2$ $2\pi r$ $r$
Square $2r$ $4r^2$ $8r$ $\sqrt{2}r$
Rectangle $l \times w$ $l \cdot w$ $2(l + w)$ $\frac{1}{2}\sqrt{l^2 + w^2}$
Equilateral Triangle $2\sqrt{3}r$ $3\sqrt{3}r^2$ $6\sqrt{3}r$ $2r$
Regular Hexagon $\frac{2\sqrt{3}r}{3}$ $2\sqrt{3}r^2$ $4\sqrt{3}r$ $\frac{2\sqrt{3}r}{3}$

3D Solid Formulas

Solid Slant Height ($s$) Lateral Area ($A_L$) Total Surface Area ($A_T$) Volume ($V$)
Sphere — $4\pi r^2$ $4\pi r^2$ $\frac{4}{3}\pi r^3$
Cylinder / Prism $h$ $P \cdot h$ $2A_B + A_L$ $A_B \cdot h$
Cone / Regular Pyramid $\sqrt{h^2 + r^2}$ $\frac{1}{2} P \cdot s$ $A_B + A_L$ $\frac{1}{3} A_B \cdot h$
Rectangular Pyramid $s_l = \sqrt{h^2 + (w/2)^2}$
$s_w = \sqrt{h^2 + (l/2)^2}$
$l \cdot s_l + w \cdot s_w$ $l \cdot w + A_L$ $\frac{1}{3} l \cdot w \cdot h$
Frustum $\sqrt{h^2 + (r_1 - r_2)^2}$ $\frac{1}{2}(P_1 + P_2)s$ $A_{B1} + A_{B2} + A_L$ $\frac{h}{3}\left(A_{B1} + A_{B2} + \sqrt{A_{B1}A_{B2}}\right)$

🏗 Project Architecture

Spatial-Geometry/
├── spatial_geometry/
│   ├── __init__.py      # Public package API
│   ├── engine.py        # Pure SymPy symbolic & numerical geometry engine
│   ├── viz.py           # 3D polygon vertex & mesh generation (Matplotlib & Plotly)
│   └── ui.py            # PyQt6 desktop GUI & QSS styling
├── geometry.py          # Desktop application entrypoint
├── app.py               # Streamlit + Plotly 3D web application entrypoint
├── tests/
│   └── test_engine.py   # Pytest suite verifying symbolic math, meshes, and UI
├── assets/
│   └── preview.png      # 3D solid gallery showcase
├── pyproject.toml       # Modern Python package & test configuration
└── requirements.txt     # Pinned runtime & test dependencies

🛠 Tech Stack

Component Technology Role
Language Python 3.10+ Type-annotated core logic and modular package
Symbolic Math SymPy Exact rational arithmetic, radical simplification, and $\LaTeX$
Desktop GUI PyQt6 + Matplotlib Native dark-mode desktop interface & 3D surface/cap rendering
Web App Streamlit + Plotly Browser-based interactive 3D solid explorer
Testing & CI Pytest + GitHub Actions Automated verification of mathematical identities & 3D meshes

📦 Installation & Usage

1. Clone & Install Dependencies

git clone https://github.com/cunhanina/Spatial-Geometry.git
cd Spatial-Geometry
pip install -r requirements.txt

2. Run the Desktop Application (PyQt6)

python geometry.py

3. Run the Interactive Web App (Streamlit + Plotly 3D)

streamlit run app.py

4. Use as a Python Library

from spatial_geometry import GeometryInput, calculate_solid, format_math, format_decimal

result = calculate_solid(GeometryInput(shape="Cone", r1="5", h="10"))
print(format_math(result.lateral_area))     # 25·√5·π
print(format_decimal(result.lateral_area))  # 175.6204

5. Run the Automated Test Suite

pytest -v

Built with ❤️ by Nina Cunha

Data Science · Industrial Automation · Software Engineering

LinkedIn GitHub

About

A Python-based spatial geometry calculator using SymPy to compute exact areas and volumes with symbolic variables like π and square roots.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages