ParanoidPanda

Untitled

Nov 16th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct point{
  5. float x;
  6. float y;
  7. };
  8.  
  9. point *arrayofpoints;
  10. point dot;
  11.  
  12.  
  13. point *loadthis(const char*filename, int countofpoints);
  14. void checkthis(int countofpoints);
  15.  
  16. int main(){
  17. int countofpoints = 0;
  18. printf("Enter the number of vertices : ");
  19. scanf("%d", &countofpoints);
  20. arrayofpoints = (point *)malloc(countofpoints * sizeof(point));
  21. if (countofpoints >= 3){
  22. arrayofpoints = (point *)malloc(countofpoints * sizeof(point));
  23. loadthis("ourfigure.txt", countofpoints);
  24. printf("Enter the top of which we will seek (x y): ");
  25. scanf("%f %f", &dot.x, &dot.y);
  26. checkthis(countofpoints);
  27. free(arrayofpoints);
  28. }
  29. else
  30. printf("Enter 3 or more vertices\n");
  31. return 0;
  32. }
  33.  
  34. point *loadthis(const char*filename, int countofpoints){
  35. FILE *input = fopen(filename, "r");
  36. if (input == NULL){
  37. printf("Cannot open input file \n");
  38. exit(0);
  39. }
  40. else{
  41. for (int i = 0; i < countofpoints; i++){
  42. fscanf(input, "%f %f", &arrayofpoints[i].x, &arrayofpoints[i].y);
  43. }
  44. printf("Our points : \n");
  45. printf("Number x y \n");
  46. for (int i = 0; i < countofpoints; i++){
  47. printf("point[%d] : %f %f\n", i, arrayofpoints[i].x, arrayofpoints[i].y);
  48. }
  49. }
  50. return arrayofpoints;
  51. }
  52.  
  53. void checkthis(int countofpoints){
  54. bool result = false;
  55. int j = countofpoints - 1;
  56. //check dot in figure
  57. for (int i = 0; i < countofpoints; i++) {
  58. if ((arrayofpoints[i].y < dot.y && arrayofpoints[j].y >= dot.y || arrayofpoints[j].y < dot.y && arrayofpoints[i].y >= dot.y) &&
  59. (arrayofpoints[i].x + (dot.y - arrayofpoints[i].y) / (arrayofpoints[j].y - arrayofpoints[i].y) * (arrayofpoints[j].x - arrayofpoints[i].x) < dot.x))
  60. result = true;
  61. j = i;
  62. }
  63. //check dot in dot
  64. if (result == false)
  65. for (int i = 0; i < countofpoints; i++){
  66. if (arrayofpoints[i].y == dot.y && arrayofpoints[i].x == dot.x)
  67. result = true;
  68. }
  69. //check dot in line
  70. if (result == false)
  71. for (int i = 0; i < countofpoints - 1; i++){
  72. if (((dot.y - arrayofpoints[i].y) / (arrayofpoints[i + 1].y - arrayofpoints[i].y)) == ((dot.x - arrayofpoints[i].x) / (arrayofpoints[i + 1].x - arrayofpoints[i].x)))
  73. result = true;
  74. }
  75. if (result == false)
  76. printf("No");
  77. else printf("Yes");
  78. }
Advertisement
Add Comment
Please, Sign In to add comment