Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "allthings.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct point *arrayofpoints;
- struct point dot;
- struct point *loadthis(const char*filename, struct point *arrrrr){
- countofpoints = 0;
- FILE *input = fopen(filename, "r");
- if (input == NULL){
- printf("Cannot open input file \n");
- exit(0);
- }
- else{
- int counter = 0;
- while (!feof(input)){
- if (fgetc(input) == '\n')
- counter++;
- }
- fseek(input, 0, SEEK_SET);
- countofpoints = counter + 1;
- arrayofpoints = (struct point *)malloc(countofpoints * sizeof(struct point));
- for (int i = 0; i < countofpoints; i++){
- fscanf(input, "%f %f", &arrayofpoints[i].x, &arrayofpoints[i].y);
- }
- printf("Our points : \n");
- for (int i = 0; i < countofpoints; i++){
- printf("struct point[%d] : %f %f\n", i, arrayofpoints[i].x, arrayofpoints[i].y);
- }
- }
- return arrayofpoints;
- }
- int checkthis(struct point *arrrrr, float x, float y){
- int result = 1;
- int j = countofpoints - 1;
- //check dot in figure
- for (int i = 0; i < countofpoints; i++) {
- if ((arrrrr[i].y < y && arrrrr[j].y >= y || arrrrr[j].y < y && arrrrr[i].y >= y) &&
- (arrrrr[i].x + (y - arrrrr[i].y) / (arrrrr[j].y - arrrrr[i].y) * (arrrrr[j].x - arrrrr[i].x) < y))
- result = 0;
- j = i;
- }
- //check dot in dot
- if (result == 1)
- for (int i = 0; i < countofpoints; i++){
- if (arrayofpoints[i].y == y && arrayofpoints[i].x == x)
- result = 0;
- }
- //check dot in line
- if (result == 1)
- for (int i = 0; i < countofpoints - 1; i++){
- if (((y - arrrrr[i].y) / (arrrrr[i + 1].y - arrrrr[i].y)) == ((x - arrrrr[i].x) / (arrrrr[i + 1].x - arrrrr[i].x)))
- result = 0;
- }
- if (result == 1)
- return 1;
- else return 0;
- }
- void seconddir(){
- int target = 1;
- char numb1[20];
- char numb2[20];
- int counterofpoints = 0;
- loadthis("ourfigure.txt", counterofpoints, arrayofpoints);
- while (target == 1){
- printf("x y: ");
- scanf("%s", &*numb1);
- if (!strcmp(numb1, "end")){
- target = 0;
- break;
- }
- scanf("%s", &*numb2);
- dot.x = atof(numb1);
- dot.y = atof(numb2);
- if (checkthis(arrayofpoints, counterofpoints, dot.x, dot.y) == 0)
- printf("YES!\n");
- else
- printf("NO\n");
- }
- free(arrayofpoints);
- }
- void thirddir(){
- int target = 1;
- int targett = 1;
- char numb1[20];
- char numb2[20];
- char numb3[20];
- int counterofpoints = 0;
- while (target == 1){
- printf("x y z: ");
- scanf("%s", &*numb1);
- if (!strcmp(numb1, "end")){
- target = 0;
- break;
- }
- scanf("%s", &*numb2);
- scanf("%s", &*numb3);
- dot.x = atof(numb1);
- dot.y = atof(numb2);
- dot.z = atof(numb3);
- loadthis("top.txt", counterofpoints, arrayofpoints);
- if (checkthis(arrayofpoints, counterofpoints, dot.x, dot.z) == 1)
- targett = 1;
- free(arrayofpoints);
- loadthis("left.txt", counterofpoints, arrayofpoints);
- if (checkthis(arrayofpoints, counterofpoints, dot.z, dot.y) == 1)
- targett = 1;
- free(arrayofpoints);
- loadthis("front.txt", counterofpoints, arrayofpoints);
- if (checkthis(arrayofpoints, counterofpoints, dot.x, dot.y) == 1)
- targett = 1;
- free(arrayofpoints);
- if (targett == 0)
- printf("YES!\n");
- else
- printf("NO\n");
- targett = 0;
- }
- }
- void menu(){
- printf("\n\n\n\t\MENU\n");
- printf("Work with 2D{1}\n");
- printf("Work with 3D{2}\n");
- int choose = 0;
- scanf("%d", &choose);
- switch (choose){
- case(1) : {
- seconddir();
- menu();
- break;
- }
- case(2) : {
- thirddir();
- menu();
- break;
- } break;
- default:{
- printf("Bad choose!\n");
- menu();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment