hdu 2108

向量叉积判断多边形凹凸性

code:

#include <iostream>
#include "math.h"
using namespace std;
const double eps = 1e-10; 
struct point{ int x,y; }; 

int crossProduct(point a,point b,point c)//叉乘 
{ return (c.x - a.x)*(b.y - a.y) - (b.x - a.x)*(c.y - a.y); 
} //
int main(int argc, char *argv[])
{
	int n;
	while(scanf("%d",&n)&&n)
	{
		point a,b,c,x,y;
		scanf("%d%d%d%d",&a.x,&a.y,&b.x,&b.y);
		n-=2;
		x=a;
		y=b;
		int flag=0;
		while(n--)
		{
			scanf("%d%d",&c.x,&c.y);
			if(crossProduct(a,b,c)>0) flag=1;
			a=b;
			b=c;
			
		}
		if(crossProduct(b,c,x)>0) flag=1;
		if(crossProduct(c,x,y)>0) flag=1;
		//if(crossProduct(x,y,a)>0) flag=1;
		if(flag==0)
		{
			cout<<"convex"<<endl;
		}else
		{
			cout<<"concave"<<endl;
		}
	}
	return 0;
}



你可能感兴趣的:(hdu 2108)