矢量的叉积,来判断拐向。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct coordinate
{
double x;
double y;
};
int cross(coordinate p1,coordinate p2,coordinate p3)
{
if((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y)>0)
return 1;
else
return 0;
}
int main()
{
//freopen("Input.txt","r",stdin);
int n;
while(cin>>n,n)
{
coordinate *point=new coordinate[n];
for(int i=0;i<n;i++)
cin>>point[i].x>>point[i].y;
int flag=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
if(j!=i&&j!=(i+1)%n)
{
int mark=cross(point[i],point[(i+1)%n],point[(i+2)%n]);
if(cross(point[i],point[(i+1)%n],point[j])!=mark)
{
flag=0;
break;
}
}
if(!flag) break;
}
if(flag) cout<<"convex"<<endl;
else cout<<"concave"<<endl;
}
}