There are 3 C++ code files in src/.
trajectory_common.hpp: The header file used by both.cppfile. Provides some basic definitions and configurations for the two code files below. This header exists to provide tidiness, avoiding writing the shared configurations separately and repeatedly in the two code files.main.cpp: The main program code to read the original video, extract the trajectory, fit parameters required in the task, and save these parameters tooutput/trajectory_result.csv.verify_plot.cpp: The code to verify the fitting result by plotting the fitted trajectory in the original video after reading the results stored inoutput/trajectory_result.csv, and save it tooutput/trajectory_result.mp4.
-
output/trajectory_result.csv: Parameters of the fitted model, including$v_{x0}, v_{y0}, g, k$ . -
output/trajectory_result.mp4: The fitted trajectory video. Can be opened with VLC Media Player. -
output/trajectory_command_line.txt: Full command line outputs oftime ./mainandtime ./verify_draw. Screenshots are as follows:
- Misunderstanding the usage of template parameters for the auto-differentiation Functor. The correct usage is detailed in the official documentation 1.
- Formula error: A minor error existed in the formula for calculating each coordinate point. However, this bug took hours to identify due to its extreme subtlety, making it difficult to detect initially.
Of the two issues above, the first one is easier to spot and is finally solved by looking up in the official documents; the second one is harder to find out, but was fixed in seconds.
Efficiency improvements:
- Pre-allocating memory for
std::vectors usingreserve. - Making functions
inlineat where performance is critical. - Un-sync
std::cin, std::coutwith stdio, because no C-style IO is used.
Footnotes
-
Ceres AutoDiffCostFunction: http://ceres-solver.org/nnls_modeling.html#_CPPv4N5ceres20AutoDiffCostFunctionE ↩

