Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct point{
- float x;
- float y;
- };
- point *arrayofpoints;
- point dot;
- point *loadthis(const char*filename, int countofpoints);
- void checkthis(int countofpoints);
- int main(){
- int countofpoints = 0;
- printf("Enter the number of vertices : ");
- scanf("%d", &countofpoints);
- arrayofpoints = (point *)malloc(countofpoints * sizeof(point));
- if (countofpoints >= 3){
- arrayofpoints = (point *)malloc(countofpoints * sizeof(point));
- loadthis("ourfigure.txt", countofpoints);
- printf("Enter the top of which we will seek (x y): ");
- scanf("%f %f", &dot.x, &dot.y);
- checkthis(countofpoints);
- free(arrayofpoints);
- }
- else
- printf("Enter 3 or more vertices\n");
- return 0;
- }
- point *loadthis(const char*filename, int countofpoints){
- FILE *input = fopen(filename, "r");
- if (input == NULL){
- printf("Cannot open input file \n");
- exit(0);
- }
- else{
- for (int i = 0; i < countofpoints; i++){
- fscanf(input, "%f %f", &arrayofpoints[i].x, &arrayofpoints[i].y);
- }
- printf("Our points : \n");
- printf("Number x y \n");
- for (int i = 0; i < countofpoints; i++){
- printf("point[%d] : %f %f\n", i, arrayofpoints[i].x, arrayofpoints[i].y);
- }
- }
- return arrayofpoints;
- }
- void checkthis(int countofpoints){
- bool result = false;
- int j = countofpoints - 1;
- //check dot in figure
- for (int i = 0; i < countofpoints; i++) {
- if ((arrayofpoints[i].y < dot.y && arrayofpoints[j].y >= dot.y || arrayofpoints[j].y < dot.y && arrayofpoints[i].y >= dot.y) &&
- (arrayofpoints[i].x + (dot.y - arrayofpoints[i].y) / (arrayofpoints[j].y - arrayofpoints[i].y) * (arrayofpoints[j].x - arrayofpoints[i].x) < dot.x))
- result = true;
- j = i;
- }
- //check dot in dot
- if (result == false)
- for (int i = 0; i < countofpoints; i++){
- if (arrayofpoints[i].y == dot.y && arrayofpoints[i].x == dot.x)
- result = true;
- }
- //check dot in line
- if (result == false)
- for (int i = 0; i < countofpoints - 1; i++){
- 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)))
- result = true;
- }
- if (result == false)
- printf("No");
- else printf("Yes");
- }
Advertisement
Add Comment
Please, Sign In to add comment