fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #ifndef M_PI
  5. #define M_PI 3.14159265358979323846
  6. #endif
  7.  
  8. typedef struct {
  9. float x, y;
  10. } Point;
  11.  
  12. Point get_rotation(Point start, Point center, float rad) {
  13. Point res;
  14. res.x = (start.x - center.x) * cos(rad) - (start.y - center.y) * sin(rad) + center.x;
  15. res.y = (start.x - center.x) * sin(rad) + (start.y - center.y) * cos(rad) + center.y;
  16. return res;
  17. }
  18.  
  19. void calc(Point gaze_start, Point gaze_end, int fov_degree) {
  20.  
  21. float rad = M_PI * fov_degree / 360;
  22. Point fov_p1 = get_rotation(gaze_end, gaze_start, rad);
  23. Point fov_p2 = get_rotation(gaze_end, gaze_start, -rad);
  24. printf("fov_p1: %.2f %.2f\n", fov_p1.x, fov_p1.y);
  25. printf("fov_p2: %.2f %.2f\n", fov_p2.x, fov_p2.y);
  26. }
  27.  
  28. int main(void) {
  29. Point gaze_start = {669,82};
  30. Point gaze_end = {289,644};
  31. calc(gaze_start, gaze_end, 45);
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
fov_p1: 102.86 455.80
fov_p2: 532.99 746.64