Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #define OK 0
  3. #define ERROR_INPUT 1
  4. #define TRIANGLE_NOT_EXIST 2
  5. #define CORRECT_COUNT_OF_VARIABLES 6
  6. #define OBTUSE 2
  7. #define ACUTE 0
  8. #define STRAIGHT 1
  9.  
  10. int triangle_type(float product_of_vectors)
  11. {
  12.     if (0 == product_of_vectors)
  13.     {
  14.         return STRAIGHT;
  15.     }
  16.     else if (product_of_vectors < 0)
  17.     {
  18.         return ACUTE;
  19.     }
  20.     else
  21.     {
  22.         return OBTUSE;
  23.     }
  24. }
  25.  
  26. float vec_calc(float vec_coord_first, float vec_coord_second)
  27. {  
  28.     float vector = vec_coord_second - vec_coord_first;
  29.  
  30.     return vector;
  31. }
  32.  
  33. float vec_scalar_product(float x_vec_first, float x_vec_second, float y_vec_first, float y_vec_second)
  34. {
  35.     float scalar_product = x_vec_first * x_vec_second + y_vec_first * y_vec_second;
  36.  
  37.     return scalar_product;
  38. }
  39.  
  40. float calc_vec_product(float x1, float y1, float x2, float y2, float x3, float y3)
  41. {
  42.     float scalar_product_ab_bc = vec_scalar_product(vec_calc(x2, x1),
  43.         vec_calc(x3, x2), vec_calc(y2, y1), vec_calc(y3, y2));
  44.     float scalar_product_ab_ca = vec_scalar_product(vec_calc(x2, x1),
  45.         vec_calc(x1, x3), vec_calc(y2, y1), vec_calc(y1, y3));
  46.     float scalar_product_bc_ca = vec_scalar_product(vec_calc(x3, x2),
  47.         vec_calc(x1, x3), vec_calc(x3, x2), vec_calc(y1, y3));
  48.     float product_of_vectors = scalar_product_ab_bc * scalar_product_ab_ca * scalar_product_bc_ca;
  49.    
  50.     return product_of_vectors;
  51. }
  52.  
  53. int existence_check(float x1, float x2, float x3, float y1, float y2, float y3)
  54. {
  55.     if ((x3 - x1) * (y3 - y2) == (x3 - x2) * (y3 - y1))
  56.     {
  57.         return TRIANGLE_NOT_EXIST;
  58.     }
  59.     else
  60.     {
  61.         return OK;
  62.     }
  63. }
  64.  
  65.  
  66. int main()
  67. {
  68.     setbuf(stdout, NULL);
  69.  
  70.     float x1 = 0, y1 = 0;
  71.     float x2 = 0, y2 = 0;
  72.     float x3 = 0, y3 = 0;
  73.  
  74.     puts("Enter vertex coordinates: ");
  75.     int check_count = scanf("%f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3);        
  76.  
  77.     if (check_count < CORRECT_COUNT_OF_VARIABLES)
  78.     {
  79.         return ERROR_INPUT;
  80.     }
  81.  
  82.     int triangle_check = existence_check(x1, x2, x3, y1, y2, y3);
  83.  
  84.     if (triangle_check != OK)
  85.     {
  86.         return triangle_check;
  87.     }
  88.    
  89.     float product_of_vectors = calc_vec_product(x1, y1, x2, y2, x3, y3);
  90.  
  91.     printf("Triangle type: %d", triangle_type(product_of_vectors));
  92.  
  93.     return OK;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement