Skip to content

Commit

Permalink
update examples + README
Browse files Browse the repository at this point in the history
  • Loading branch information
gdifiore committed Aug 3, 2024
1 parent f7f1e34 commit eeab463
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ set(TEST_SOURCES
add_executable(libshotscope_tests ${TEST_SOURCES})
target_link_libraries(libshotscope_tests ${PROJECT_NAME} GTest::gtest_main)

add_executable(main examples/main.cpp)
target_link_libraries(main ${PROJECT_NAME})
# Eamples
add_executable(calculate_ball_landing examples/calculate_ball_landing.cpp)
target_link_libraries(calculate_ball_landing ${PROJECT_NAME})

add_executable(calculate_ball_trajectory examples/calculate_ball_trajectory.cpp)
target_link_libraries(calculate_ball_trajectory ${PROJECT_NAME})

# Discover tests
include(GoogleTest)
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# libshotscope
libshotscope - (wip) golf ball trajectory calculation
libshotscope - golf ball trajectory calculation

Much of the 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. I turned it into a C++ library and incorporated tests.

See `examples/`.

## Build
```
chmod +x build.sh
Expand Down
4 changes: 0 additions & 4 deletions TODO

This file was deleted.

File renamed without changes.
26 changes: 26 additions & 0 deletions examples/calculate_ball_trajectory.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "Simulator.hpp"
#include "golf_ball.hpp"
#include "atmosphere.hpp"
#include "math_utils.hpp"

int main()
{
const golfBall ball{0.0, 0.0, 0.0, 160.0, 11.0, 0.0, 3000.0, 0.0};
const atmosphericData atmos{70.0, 0.0, 0.0, 0.0, 0.0, 50.0, 29.92};

GolfBallPhysicsVariables physVars(ball, atmos);
GolfBallFlight flight(physVars, ball, atmos);

Simulator simulator(physVars, flight);

std::vector<Vector3D> result = simulator.runSimulation();

printf("Entire ball trajectory");

for (const auto& entry : result)
{
printf("%.1f %.1f %.1f\n", entry[0]/math_utils::YARDS_TO_FEET, entry[1]/math_utils::YARDS_TO_FEET, entry[2]/math_utils::YARDS_TO_FEET);
}

return 0;
}

0 comments on commit eeab463

Please sign in to comment.