{"id":28235299,"url":"https://github.com/klaudiusz321/raytracing-engine-in-c","last_synced_at":"2025-06-13T03:30:46.086Z","repository":{"id":287577737,"uuid":"965168146","full_name":"Klaudiusz321/raytracing-engine-in-c","owner":"Klaudiusz321","description":"🚀 Black Hole Physics Engine: A C-based engine simulating realistic black hole physics, including ray tracing, particle orbits, accretion disks, and Hawking radiation effects.","archived":false,"fork":false,"pushed_at":"2025-04-27T17:21:07.000Z","size":7128,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-18T23:11:35.417Z","etag":null,"topics":["api","engine","physics"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Klaudiusz321.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-12T15:06:15.000Z","updated_at":"2025-05-02T08:59:06.000Z","dependencies_parsed_at":"2025-04-12T16:27:53.993Z","dependency_job_id":"062db115-d144-4799-a710-760a382e74ca","html_url":"https://github.com/Klaudiusz321/raytracing-engine-in-c","commit_stats":null,"previous_names":["klaudiusz321/raytracing-engine-in-c"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Klaudiusz321/raytracing-engine-in-c","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Klaudiusz321%2Fraytracing-engine-in-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Klaudiusz321%2Fraytracing-engine-in-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Klaudiusz321%2Fraytracing-engine-in-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Klaudiusz321%2Fraytracing-engine-in-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Klaudiusz321","download_url":"https://codeload.github.com/Klaudiusz321/raytracing-engine-in-c/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Klaudiusz321%2Fraytracing-engine-in-c/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259573586,"owners_count":22878530,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","engine","physics"],"created_at":"2025-05-18T23:11:24.171Z","updated_at":"2025-06-13T03:30:46.060Z","avatar_url":"https://github.com/Klaudiusz321.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Black Hole Physics Simulation Engine\r\n\r\n![Black Hole Simulation](https://via.placeholder.com/800x400?text=Black+Hole+Simulation)\r\n\r\n## Overview\r\n\r\nThis project implements a physics-accurate black hole simulation engine with real-time ray tracing capabilities. It models how light and matter behave in the curved spacetime around black holes, visualizing phenomena like gravitational lensing, accretion disks, relativistic effects, and particle orbits.\r\n\r\n## Features\r\n\r\n- **Relativistic Ray Tracing**: Accurate simulation of photon paths in curved spacetime using geodesic equations\r\n- **Accretion Disk Simulation**: Realistic visualization of matter orbiting black holes\r\n- **Particle Orbit Calculator**: Computation of stable and unstable orbits around black holes\r\n- **Relativistic Effects**: Visualization of:\r\n  - Gravitational lensing\r\n  - Gravitational redshift\r\n  - Doppler shift and relativistic beaming\r\n  - Time dilation\r\n- **Multiple Integration Methods**:\r\n  - 4th-order Runge-Kutta (RK4)\r\n  - Adaptive Runge-Kutta-Fehlberg (RKF45)\r\n  - Leapfrog integration\r\n  - Symplectic integrators\r\n\r\n## Technical Architecture\r\n\r\nThe engine is implemented in C for performance, with a modular architecture:\r\n\r\n- **Core Modules**:\r\n  - `spacetime.c`: Implements the mathematical models for curved spacetime (Schwarzschild and Kerr metrics)\r\n  - `raytracer.c`: Handles light ray propagation through curved spacetime\r\n  - `particle_sim.c`: Simulates massive particles orbiting black holes\r\n  - `math_util.c`: Mathematical utilities, including vector operations and numerical integrators\r\n  - `blackhole_api.c`: High-level API for application integration\r\n\r\n- **Numerical Methods**:\r\n  The engine provides multiple integration methods for solving the geodesic equations, balancing accuracy and performance.\r\n\r\n## Building the Project\r\n\r\n### Prerequisites\r\n\r\n- C compiler (GCC or Clang recommended)\r\n- OpenMP support (optional, for multi-threading)\r\n\r\n### Compilation\r\n\r\n```bash\r\ngcc -Wall -Iinclude -o blackhole_sim.exe src/main.c src/math_util.c src/spacetime.c src/raytracer.c src/particle_sim.c src/blackhole_api.c\r\n```\r\n\r\nFor optimized build with OpenMP support:\r\n\r\n```bash\r\ngcc -O3 -fopenmp -Wall -Iinclude -o blackhole_sim.exe src/main.c src/math_util.c src/spacetime.c src/raytracer.c src/particle_sim.c src/blackhole_api.c\r\n```\r\n\r\n## Usage Examples\r\n\r\n### Basic Simulation\r\n\r\n```c\r\n// Initialize black hole parameters\r\nBlackHoleParams blackhole;\r\nblackhole.mass = 1.0;  // Mass in geometric units (M)\r\nblackhole.spin = 0.0;  // Non-rotating Schwarzschild black hole\r\nblackhole.schwarzschild_radius = 2.0 * blackhole.mass;\r\n\r\n// Configure simulation\r\nSimulationConfig config;\r\nconfig.max_integration_steps = 1000;\r\nconfig.time_step = 0.1;\r\nconfig.tolerance = 1e-6;\r\nconfig.max_ray_distance = 100.0;\r\n\r\n// Create a ray\r\nRay ray;\r\nray.origin = (Vector3D){0.0, 0.0, 30.0};  // Starting 30M away from black hole\r\nray.direction = (Vector3D){0.0, 0.0, -1.0};  // Pointing toward black hole\r\n\r\n// Trace the ray\r\nRayTraceHit hit;\r\nRayTraceResult result = trace_ray(\u0026ray, \u0026blackhole, NULL, \u0026config, \u0026hit);\r\n\r\n// Print results\r\nprintf(\"Ray result: %d\\n\", result);\r\nprintf(\"Hit position: (%.2f, %.2f, %.2f)\\n\", \r\n       hit.hit_position.x, hit.hit_position.y, hit.hit_position.z);\r\nprintf(\"Distance traveled: %.3f\\n\", hit.distance);\r\n```\r\n\r\n### Visualizing an Accretion Disk\r\n\r\n```c\r\n// Create accretion disk parameters\r\nAccretionDiskParams disk;\r\ndisk.inner_radius = 3.0 * blackhole.mass;  // Inner edge at ISCO\r\ndisk.outer_radius = 20.0 * blackhole.mass;\r\ndisk.temperature_scale = 1.0;\r\n\r\n// Trace rays with disk intersection check\r\nRayTraceResult result = trace_ray(\u0026ray, \u0026blackhole, \u0026disk, \u0026config, \u0026hit);\r\n\r\nif (result == RAY_DISK) {\r\n    // Calculate disk temperature and color at hit position\r\n    double temperature;\r\n    double color[3];\r\n    calculate_disk_temperature(\u0026hit.hit_position, \u0026blackhole, \u0026disk, \u0026temperature, color);\r\n    \r\n    // Apply relativistic effects to color\r\n    apply_relativistic_effects(\u0026hit.hit_position, \u0026ray.direction, \u0026blackhole, color, NULL);\r\n    \r\n    // Use color for rendering\r\n    printf(\"Disk hit color: RGB(%.2f, %.2f, %.2f)\\n\", color[0], color[1], color[2]);\r\n}\r\n```\r\n\r\n## Performance Optimization\r\n\r\nThe engine incorporates several performance optimizations:\r\n\r\n- **SIMD Vector Operations**: Accelerated vector math using CPU SIMD instructions when available\r\n- **Multi-threading**: Parallel ray tracing using OpenMP\r\n- **Adaptive Step Size**: RKF45 integrator adjusts step size based on local error\r\n- **Efficient Memory Management**: Minimizes allocations during critical processing\r\n\r\n## Development Status\r\n\r\nThis project is currently in active development. Key areas of ongoing work:\r\n\r\n- Adding support for rotating (Kerr) black holes\r\n- Implementing more sophisticated accretion disk models\r\n- Improving numerical stability in extreme gravity regions\r\n- Adding GPU acceleration for real-time visualization\r\n\r\n## License\r\n\r\n[MIT License](LICENSE) - Feel free to use, modify, and distribute this code.\r\n\r\n## Acknowledgments\r\n\r\nThis project draws inspiration from:\r\n- The work of Kip Thorne and the visual effects team for the movie \"Interstellar\"\r\n- Olli Seiskari's real-time black hole visualization techniques\r\n- Academic papers on numerical relativity and black hole physics\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to submit a Pull Request.\r\n\r\n## Directory Structure\r\n\r\n```\r\n├── include/              # Header files\r\n│   ├── blackhole_api.h   # Public API\r\n│   ├── blackhole_types.h # Common type definitions\r\n│   ├── math_util.h       # Mathematical utilities\r\n│   ├── particle_sim.h    # Particle simulation\r\n│   ├── raytracer.h       # Ray tracing\r\n│   └── spacetime.h       # Spacetime geometry\r\n├── src/                  # Source files\r\n├── bin/                  # Compiled binaries\r\n├── lib/                  # Libraries\r\n├── tests/                # Test files\r\n├── Makefile              # Build system\r\n└── README.md             # This file\r\n```\r\n\r\n## Building\r\n\r\n### Requirements\r\n\r\n- C compiler (GCC or Clang)\r\n- Make\r\n\r\n### Build Commands\r\n\r\n```bash\r\n# Build the default executable\r\nmake\r\n\r\n# Create a static library\r\nmake lib\r\n\r\n# Clean the build\r\nmake clean\r\n\r\n# Rebuild everything\r\nmake rebuild\r\n\r\n# Run the test program\r\nmake run\r\n\r\n# Build WebAssembly version (requires Emscripten)\r\nmake wasm\r\n```\r\n\r\n## Using the Library\r\n\r\nThe library provides a simple API for integrating into your applications. Here's a quick example:\r\n\r\n```c\r\n#include \"blackhole_api.h\"\r\n\r\n// Initialize the engine\r\nBHContextHandle context = bh_initialize();\r\n\r\n// Configure black hole parameters\r\nbh_configure_black_hole(context, 1.0, 0.0, 0.0);  // Mass, spin, charge\r\n\r\n// Configure accretion disk\r\nbh_configure_accretion_disk(context, 6.0, 20.0, 1.0, 1.0);\r\n\r\n// Trace a ray\r\nRay ray = {\r\n    .origin = {0.0, 0.0, 30.0},\r\n    .direction = {0.1, 0.0, -1.0}\r\n};\r\nRayTraceHit hit;\r\nbh_trace_ray(context, ray.origin, ray.direction, \u0026hit);\r\n\r\n// Clean up\r\nbh_shutdown(context);\r\n```\r\n\r\n## Science Behind the Simulation\r\n\r\nThe simulation implements various aspects of general relativity, including:\r\n\r\n- **Geodesic Equation** for tracing light paths in curved spacetime\r\n- **Schwarzschild Metric** for modeling the spacetime around a non-rotating black hole\r\n- **Kerr Metric** for rotating black holes (partial implementation)\r\n- **Relativistic Doppler and Gravitational Redshift** for accretion disk visualization\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the LICENSE file for details.\r\n\r\n## Acknowledgments\r\n\r\nThis project draws inspiration from various scientific visualizations and simulations of black holes, including work by NASA's Goddard Space Flight Center and Kip Thorne's work for the movie \"Interstellar\".","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklaudiusz321%2Fraytracing-engine-in-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklaudiusz321%2Fraytracing-engine-in-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklaudiusz321%2Fraytracing-engine-in-c/lists"}