ParanoidPanda

Untitled

Jan 8th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. #include "allthings.h"
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. struct point *arrayofpoints;
  8. struct point dot;
  9.  
  10.  
  11. struct point *loadthis(const char*filename, struct point *arrrrr){
  12. countofpoints = 0;
  13. FILE *input = fopen(filename, "r");
  14. if (input == NULL){
  15. printf("Cannot open input file \n");
  16. exit(0);
  17. }
  18. else{
  19. int counter = 0;
  20. while (!feof(input)){
  21. if (fgetc(input) == '\n')
  22. counter++;
  23. }
  24. fseek(input, 0, SEEK_SET);
  25. countofpoints = counter + 1;
  26. arrayofpoints = (struct point *)malloc(countofpoints * sizeof(struct point));
  27. for (int i = 0; i < countofpoints; i++){
  28. fscanf(input, "%f %f", &arrayofpoints[i].x, &arrayofpoints[i].y);
  29. }
  30. printf("Our points : \n");
  31. for (int i = 0; i < countofpoints; i++){
  32. printf("struct point[%d] : %f %f\n", i, arrayofpoints[i].x, arrayofpoints[i].y);
  33. }
  34. }
  35. return arrayofpoints;
  36. }
  37.  
  38. int checkthis(struct point *arrrrr, float x, float y){
  39. int result = 1;
  40. int j = countofpoints - 1;
  41. //check dot in figure
  42. for (int i = 0; i < countofpoints; i++) {
  43. if ((arrrrr[i].y < y && arrrrr[j].y >= y || arrrrr[j].y < y && arrrrr[i].y >= y) &&
  44. (arrrrr[i].x + (y - arrrrr[i].y) / (arrrrr[j].y - arrrrr[i].y) * (arrrrr[j].x - arrrrr[i].x) < x))
  45. result = 0;
  46. j = i;
  47. }
  48. //check dot in dot
  49. if (result == 1){
  50. for (int i = 0; i < countofpoints; i++){
  51. if (arrayofpoints[i].y == y && arrayofpoints[i].x == x){
  52. result = 0;
  53. }
  54. }
  55. }
  56. if (result == 1)
  57. return 1;
  58. else if(result == 0)
  59. return 0;
  60. }
  61.  
  62. void seconddir(){
  63. int target = 1;
  64. char numb1[20];
  65. char numb2[20];
  66. int counterofpoints = 0;
  67. loadthis("ourfigure.txt", counterofpoints, arrayofpoints);
  68.  
  69. while (target == 1){
  70. printf("x y: ");
  71. scanf("%s", &*numb1);
  72. if (!strcmp(numb1, "end")){
  73. target = 0;
  74. break;
  75. }
  76. scanf("%s", &*numb2);
  77. dot.x = atof(numb1);
  78. dot.y = atof(numb2);
  79. if (checkthis(arrayofpoints, dot.x, dot.y) == 0)
  80. printf("YES!\n");
  81. else
  82. printf("NO\n");
  83. }
  84. free(arrayofpoints);
  85. }
  86.  
  87. void thirddir(){
  88. int target = 1;
  89. int targett = 1;
  90. char numb1[20];
  91. char numb2[20];
  92. char numb3[20];
  93. int counterofpoints = 0;
  94. while (target == 1){
  95. printf("x y z: ");
  96. scanf("%s", &*numb1);
  97. if (!strcmp(numb1, "end")){
  98. target = 0;
  99. break;
  100. }
  101. scanf("%s", &*numb2);
  102. scanf("%s", &*numb3);
  103. dot.x = atof(numb1);
  104. dot.y = atof(numb2);
  105. dot.z = atof(numb3);
  106. loadthis("top.txt", counterofpoints, arrayofpoints);
  107. if (checkthis(arrayofpoints, counterofpoints, dot.x, dot.z) == 1)
  108. targett = 1;
  109. free(arrayofpoints);
  110. loadthis("left.txt", counterofpoints, arrayofpoints);
  111. if (checkthis(arrayofpoints, counterofpoints, dot.z, dot.y) == 1)
  112. targett = 1;
  113. free(arrayofpoints);
  114. loadthis("front.txt", counterofpoints, arrayofpoints);
  115. if (checkthis(arrayofpoints, counterofpoints, dot.x, dot.y) == 1)
  116. targett = 1;
  117. free(arrayofpoints);
  118. if (targett == 0)
  119. printf("YES!\n");
  120. else
  121. printf("NO\n");
  122. targett = 0;
  123. }
  124. }
  125.  
  126. void menu(){
  127. printf("\n\n\n\t\MENU\n");
  128. printf("Work with 2D{1}\n");
  129. printf("Work with 3D{2}\n");
  130. int choose = 0;
  131. scanf("%d", &choose);
  132. switch (choose){
  133. case(1) : {
  134. seconddir();
  135. menu();
  136. break;
  137. }
  138. case(2) : {
  139. thirddir();
  140. menu();
  141. break;
  142. } break;
  143. default:{
  144. printf("Bad choose!\n");
  145. menu();
  146. }
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment