#include <stdio.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
typedef struct {
float x, y;
} Point;
Point get_rotation(Point start, Point center, float rad) {
Point res;
res.
x = (start.
x - center.
x) * cos(rad
) - (start.
y - center.
y) * sin(rad
) + center.
x; res.
y = (start.
x - center.
x) * sin(rad
) + (start.
y - center.
y) * cos(rad
) + center.
y; return res;
}
void calc(Point gaze_start, Point gaze_end, int fov_degree) {
float rad = M_PI * fov_degree / 360;
Point fov_p1 = get_rotation(gaze_end, gaze_start, rad);
Point fov_p2 = get_rotation(gaze_end, gaze_start, -rad);
printf("fov_p1: %.2f %.2f\n", fov_p1.
x, fov_p1.
y); printf("fov_p2: %.2f %.2f\n", fov_p2.
x, fov_p2.
y); }
int main(void) {
Point gaze_start = {669,82};
Point gaze_end = {289,644};
calc(gaze_start, gaze_end, 45);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CgojaWZuZGVmIE1fUEkKI2RlZmluZSBNX1BJIDMuMTQxNTkyNjUzNTg5NzkzMjM4NDYKI2VuZGlmCgp0eXBlZGVmIHN0cnVjdCB7CglmbG9hdCB4LCB5Owp9IFBvaW50OwoKUG9pbnQgZ2V0X3JvdGF0aW9uKFBvaW50IHN0YXJ0LCBQb2ludCBjZW50ZXIsIGZsb2F0IHJhZCkgewoJUG9pbnQgcmVzOwoJcmVzLnggPSAoc3RhcnQueCAtIGNlbnRlci54KSAqIGNvcyhyYWQpIC0gKHN0YXJ0LnkgLSBjZW50ZXIueSkgKiBzaW4ocmFkKSArIGNlbnRlci54OwoJcmVzLnkgPSAoc3RhcnQueCAtIGNlbnRlci54KSAqIHNpbihyYWQpICsgKHN0YXJ0LnkgLSBjZW50ZXIueSkgKiBjb3MocmFkKSArIGNlbnRlci55OwoJcmV0dXJuIHJlczsKfQoKdm9pZCBjYWxjKFBvaW50IGdhemVfc3RhcnQsIFBvaW50IGdhemVfZW5kLCBpbnQgZm92X2Rl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