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 (
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:
-
Pure Rational & Symbolic Pipeline: Powered by SymPy, user inputs (including decimals and fractions like
2.5or1/3) are parsed into exactsympy.Rationalobjects before evaluation. Square roots ($\sqrt{h^2 + r^2}$ ) and constants ($\pi, \sqrt{3}$ ) remain exact throughout the calculation chain. -
Dual Symbolic + Decimal Output: Every metric displays its simplified symbolic form (
500·π/3), the governing mathematical formula, and its numerical evaluation (≈ 523.5988) simultaneously. -
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$ ).
-
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.
-
Desktop App (
| Base Shape | Side Length ( |
Base Area ( |
Perimeter ( |
3D Circumradius ( |
|---|---|---|---|---|
| Circle |
|
|||
| Square | ||||
| Rectangle | ||||
| Equilateral Triangle | ||||
| Regular Hexagon |
| Solid | Slant Height ( |
Lateral Area ( |
Total Surface Area ( |
Volume ( |
|---|---|---|---|---|
| Sphere | — | |||
| Cylinder / Prism | ||||
| Cone / Regular Pyramid | ||||
| Rectangular Pyramid |
|
|||
| Frustum |
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
| Component | Technology | Role |
|---|---|---|
| Language | Python 3.10+ | Type-annotated core logic and modular package |
| Symbolic Math | SymPy | Exact rational arithmetic, radical simplification, and |
| 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 |
git clone https://github.com/cunhanina/Spatial-Geometry.git
cd Spatial-Geometry
pip install -r requirements.txtpython geometry.pystreamlit run app.pyfrom 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.6204pytest -v