Created
June 15, 2018 13:03
-
-
Save kim366/bdd0b3ebce4be0eb3be989d569264987 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sf::Vector2f put_point_on_line(sf::Vector2f point, sf::Vector2f line_point0, sf::Vector2f line_point1) | |
| { | |
| const double new_point_x | |
| { | |
| ( | |
| point.x * std::pow(line_point0.x - line_point1.x, 2) | |
| + | |
| ( | |
| point.y * (line_point0.x - line_point1.x) | |
| - line_point0.x * line_point1.y | |
| + line_point0.y * line_point1.x | |
| ) | |
| * (line_point0.y - line_point1.y) | |
| ) | |
| / | |
| ( | |
| std::pow(line_point0.x, 2) | |
| - 2 * line_point0.x * line_point1.x | |
| + std::pow(line_point0.y, 2) | |
| - 2 * line_point0.y * line_point1.y | |
| + std::pow(line_point1.x, 2) | |
| + std::pow(line_point1.y, 2) | |
| ) | |
| }; | |
| const double new_point_y | |
| { | |
| ( | |
| ( | |
| line_point0.y - line_point1.y | |
| ) | |
| * new_point_x | |
| + line_point0.x * line_point1.y | |
| - line_point0.y * line_point1.x | |
| ) | |
| / | |
| ( | |
| line_point0.x - line_point1.x | |
| ) | |
| }; | |
| return {static_cast<float>(new_point_x), static_cast<float>(new_point_y)}; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment