A FastAPI-based backend providing endpoints for mathematical calculations, physics simulations, and data visualizations.
- Complex function visualization
- Fourier transform analysis
- Differential equation solver
- Projectile motion simulation
- Damped harmonic motion simulation
-
app/main.py
- Main FastAPI application
- Sets up CORS middleware
- Includes routers for math and physics endpoints
-
app/core/config.py
- Configuration settings using Pydantic
- Defines project name, version, and allowed origins
-
app/api/math_routes.py
- FastAPI router for math-related endpoints
- Endpoints:
- Complex function visualization
- Fourier transform
- Differential equation solver
-
app/api/physics_routes.py
- FastAPI router for physics-related endpoints
- Endpoints:
- Projectile motion
- Damped harmonic motion
-
app/services/math_service.py
- Contains functions for mathematical computations
- Implements:
- Complex function plotting
- Fourier transform calculation
- Differential equation solving
-
app/services/physics_service.py
- Contains functions for physics simulations
- Implements:
- Projectile motion calculation
- Damped harmonic motion simulation
-
app/utils/plotting.py
- Utility function to convert Matplotlib figures to base64 encoded strings
-
requirements.txt
- Lists all Python dependencies
-
Dockerfile
- Instructions for building a Docker image of the application
-
.env
- Environment variables for configuration
-
Complex Function Visualization (
math_service.py
):def generate_complex_function_plot(function_type: str, x_range: tuple, y_range: tuple): # Creates contour plots for magnitude and phase of complex functions
-
Fourier Transform (
math_service.py
):def generate_fourier_transform(signal_type: str, frequency: float, duration: float, sample_rate: float): # Generates time-domain signal and its Fourier transform
-
Differential Equation Solver (
math_service.py
):def solve_differential_equation(equation_type: str, parameters: dict, initial_conditions: list, t_span: list): # Solves different types of ODEs using scipy.integrate.odeint
-
Projectile Motion (
physics_service.py
):def simulate_projectile_motion(initial_velocity, angle_degrees, gravity=9.8): # Calculates and plots projectile motion
-
Damped Harmonic Motion (
physics_service.py
):def simulate_damped_harmonic_motion(mass: float, spring_constant: float, damping_coefficient: float, initial_displacement: float, initial_velocity: float, duration: float): # Simulates damped harmonic oscillator using odeint
-
POST /api/math/complex_function
- Visualizes complex functions
-
POST /api/math/fourier_transform
- Performs Fourier transform on various signal types
-
POST /api/math/differential_equation
- Solves and plots solutions for different types of ODEs
-
POST /api/physics/projectile_motion
- Simulates projectile motion
-
POST /api/physics/damped_harmonic_motion
- Simulates damped harmonic motion
- Install dependencies:
pip install -r requirements.txt
- Run server:
uvicorn app.main:app --reload
- Access API at
http://localhost:8000
- Build:
docker build -t math-physics-platform .
- Run:
docker run -p 8000:8000 math-physics-platform