https://github.com/gdifiore/libgolf
libgolf - golf ball trajectory calculation
https://github.com/gdifiore/libgolf
cmake cpp cpp-lib cpp-library cpp-math cpp-math-library golf math math-library oop physics simulation trajectory
Last synced: about 6 hours ago
JSON representation
libgolf - golf ball trajectory calculation
- Host: GitHub
- URL: https://github.com/gdifiore/libgolf
- Owner: gdifiore
- License: gpl-3.0
- Created: 2024-04-18T00:07:20.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2026-04-12T23:06:41.000Z (2 days ago)
- Last Synced: 2026-04-13T01:08:11.348Z (2 days ago)
- Topics: cmake, cpp, cpp-lib, cpp-library, cpp-math, cpp-math-library, golf, math, math-library, oop, physics, simulation, trajectory
- Language: C++
- Homepage: https://gdifiore.github.io/libgolf/
- Size: 485 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# libgolf
`libgolf` is a C++ library that simulates golf ball trajectories from initial conditions: velocity, spin, and atmospheric data. It computes full flight paths including aerial phase, bounce, and roll.
The in-air math here is based on [work done](http://baseball.physics.illinois.edu/trajectory-calculator-golf.html) by Prof. Alan M. Nathan at the University of Illinois Urbana-Champaign.
## Requirements
- C++20 or later
- CMake 3.14+
## Build
```bash
git clone https://github.com/gdifiore/libgolf.git
cd libgolf
chmod +x build.sh
./build.sh
```
## Features
- Full trajectory simulation with automatic phase transitions (aerial → bounce → roll)
- Dynamic ground surfaces - fairways, roughs, greens, elevation changes
- 3D terrain system with slopes and varying surface normals
- Pluggable aerodynamic model — implement custom Cd/Cl/spin-decay behaviour
- Efficient step-by-step numerical integration
## Documentation
- [Getting Started](/docs/how.md) - Basic usage and examples
- [Terrain System](/docs/terrain.md) - Custom terrain with elevation, slopes, and varying surfaces
- [Aerodynamic Models](/docs/aerodynamic_model.md) - Custom drag, lift, and spin-decay models
### Quick Example
```cpp
#include
const LaunchData ball{
.ballSpeedMph = 160.0f,
.launchAngleDeg = 11.0f,
.directionDeg = 0.0f,
.backspinRpm = 3000.0f,
.sidespinRpm = 0.0f,
};
const AtmosphericData atmos{
.temp = 70.0f,
.elevation = 0.0f,
.vWind = 0.0f,
.phiWind = 0.0f,
.hWind = 0.0f,
.relHumidity = 50.0f,
.pressure = 29.92f,
};
GroundSurface ground; // Default fairway
FlightSimulator sim(ball, atmos, ground);
sim.run();
LandingResult result = sim.getLandingResult();
printf("Distance: %.1f yards\n", result.distance);
```
For terrain with slopes or position-dependent surfaces, see the [Terrain System](/docs/terrain.md).