fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. namespace so
  5. {
  6. struct _point_2d_
  7. {
  8. float x{};
  9. float y{};
  10. };
  11.  
  12. struct _line_2d_
  13. {
  14. _point_2d_ start{};
  15. _point_2d_ end{};
  16. };
  17.  
  18. _line_2d_ create_arrow(float _angle_delta, float _length, _line_2d_ const & _base)
  19. {
  20. float angle_arrow_{std::atan2(_base.end.y - _base.start.y, _base.end.x - _base.start.x) + _angle_delta};
  21.  
  22. _line_2d_ line_arrow_{};
  23.  
  24. line_arrow_.start.x = _base.end.x;
  25. line_arrow_.start.y = _base.end.y;
  26.  
  27. line_arrow_.end.x = line_arrow_.start.x + _length * std::cos(angle_arrow_);
  28. line_arrow_.end.y = line_arrow_.start.y + _length * std::sin(angle_arrow_);
  29.  
  30. return (line_arrow_);
  31. }
  32. }
  33.  
  34. int main()
  35. {
  36. so::_line_2d_ base_{};
  37. float angle_delta_{0.5236f};
  38. float length_{1.0f};
  39.  
  40. base_.start.x = 1.0f;
  41. base_.start.y = 1.0f;
  42. base_.end.x = -1.0f;
  43. base_.end.y = 1.0f;
  44.  
  45. so::_line_2d_ arrow_counter{so::create_arrow(3.1416f - angle_delta_, length_, base_)};
  46.  
  47. std::cout << "(" << arrow_counter.start.x << ", " << arrow_counter.start.y << ") - (" << arrow_counter.end.x << ", "
  48. << arrow_counter.end.y << ")" << std::endl;
  49.  
  50. so::_line_2d_ arrow_clock{so::create_arrow(-3.1416f + angle_delta_, length_, base_)};
  51.  
  52. std::cout << "(" << arrow_clock.start.x << ", " << arrow_clock.start.y << ") - (" << arrow_clock.end.x << ", "
  53. << arrow_clock.end.y << ")" << std::endl;
  54.  
  55. return (0);
  56. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
(-1, 1) - (-0.133971, 0.500006)
(-1, 1) - (-0.133972, 1.49999)