1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include <stdio.h>
#include <math.h>
struct point
{
double x, y;
};
struct point input_point()
{
struct point a;
printf("x = ");
scanf("%lf", &a.x);
printf("y = ");
scanf("%lf", &a.y);
return a;
}
struct point reverse(struct point v)
{
struct point w;
w.x = -v.x;
w.y = -v.y;
return w;
}
struct point make_vector(struct point a, struct point b)
{
struct point v;
v.x = b.x - a.x;
v.y = b.y - a.y;
return v;
}
double dot_product(struct point a, struct point b)
{
return a.x * b.x + a.y * b.y;
}
double len(struct point v)
{
return sqrt(dot_product(v, v));
}
double v_cosine(struct point v1, struct point v2)
{
return dot_product(v1, v2) / (len(v1) * len(v2));
}
double sine_half(double cos)
{
return sqrt((1 - cos) / 2);
}
int main()
{
struct point a, b, c, ab, bc, ac;
printf("Vavedete A:\n");
a = input_point();
printf("Vavedete B:\n");
b = input_point();
printf("Vavedete C:\n");
c = input_point();
ab = make_vector(a, b);
bc = make_vector(b, c);
ac = make_vector(a, c);
printf("sin(alpha / 2) = %.4f\n", sine_half(v_cosine(ab, ac)));
printf("sin(beta / 2) = %.4f\n", sine_half(v_cosine(reverse(ab), bc)));
printf("sin(gamma / 2) = %.4f\n", sine_half(v_cosine(reverse(bc), reverse(ac))));
}
|