Hey guys,i was working on a project which is a homework, i admit , however i wrote some codes and i could not find the error in them so i'd like one of you guys to help me out there. The program will consist of getting inputs from the keyboard and will define if the given polygon is real or not and if it is concave or convex.The program i wrote get the N , side number and the coordinates of those side points.After that it'll start the function "poly" and that would divide the polygon into triangles in which i intend to use cosinus theorem to define the angle of the given point.After defining all angles , i'd check if the polygon has an angle with 180 or more degrees to define concaveness and also i should add all the angles together to see if it equals to (N-2)*180..So here is the code , btw beware that i have not written the concave/convex defining "if" and also my problem is i can define the "a,b,c" and the first angle D[0] however D[1] returns random numbers which i assume is the memory value of it.
z+=D[j];
};
for(int k=0;k<N;k++){
cout<<""<<D[k]<<endl;};
if(z==(N-2)*180){
cout<<"That is a polygon";
}
else{
cout<<"That is not a polygon";
}
;
}
int main()
{ int N;
int A[B];
int X[B];
int Y[B];
cout <<" N:";
cin >> N;
for (int i=0;i<N;i++){
cout << "Enter X=";
cin >>X[i];
cout << "Enter Y=";
cin >>Y[i];
};
X[N]=X[0];
X[N+1]=X[1];
Y[N]=Y[0];
Y[N+1]=Y[1];
poly(N,X,Y);
for(int j=0;j<N+2;j++) {
cout <<"Values:"<<X[j]<<endl;
cout <<"Values:"<<Y[j]<<endl;
};
system("PAUSE");
return EXIT_SUCCESS;
}
Also the output i get is,when i enter a triangle with coordinates 0,0 0,5 5,0 ;
D[0]=89.9638
D[1]=-1.#IND
D[2]=-1.#IND
when i check the side values of the second and third angles(a,b and c) they all appear normal. Any help would be really appreciated.
(acos)
On success, these functions return the arc cosine of x in radians; the
return value is in the range [0, pi].
If x is a NaN, a NaN is returned.
If x is +1, +0 is returned.
If x is positive infinity or negative infinity, a domain error occurs,
and a NaN is returned.
If x is outside the range [-1, 1], a domain error occurs, and a NaN is
returned.
So your method is doomed to fail.
You better use the cross product (u x v)_z = |u| |v| sin( \theta )
So looking at the sign you could tell if you turn to the right or to the left. In a convex polygon you always turn to the same side.