Originally Posted by
Salem
So post your attempt.
The polygon seems irrelevant to the problem, since all you're interested in is the boundary.
So it's really just "is a point" on a list of line segments.
Figure out the solution to "is a point on a single line segment", which is the essense of the problem.
If you can do it for one line segment, then doing it for n line segments is easy.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{ int N,counter,counter2;
double x,y,a,b;
int i,row,column,j;
printf("Enter x and y coordinates of the point whose position is investigated:");
scanf("%lf%lf",&x,&y);
printf("Enter the number of corners for the polygon:");
scanf("%d",&N);
counter=1;
if(N<=2){
counter=0;
printf ("The number of corners for creating a polygon is inadequate. ");
}
while(counter==1){
double A[2][N];
for(column=0; column<N; column++){
printf("Enter x and y coordinates of the %d.corner :",column);
for(row=0;row<2;row++)
scanf("%lf",&A[row][column]);
}
a=A[0][0];
b=A[1][0];
for (column=1;column<N;column++){
if (A[0][column]==a && A[1][column]==b){
printf("The terminal points of the line are same.These inputs do not form a line for the polygon!");
counter=0;
break;
}
else
a=A[0][column];
b=A[1][column];
}
counter2=0;
while (counter2=1){
double m,n;
for (column=0;column<N;column++){
m=(A[1][column+1]-A[1][column])-(A[0][column+1]-A[0][column]);
n=A[1][column]/(m*A[0][column]);
A[1][column+1]=(m*A[0][column+1])+n;
if(y==(m*x)+n ){
printf("the point is on the polygon");
counter2=1;
break;
}
}
}
}
}