几何问题

如果在一个二维坐标系中,已知三角形三个点的坐标,那么对于坐标系中的任意一点,如何判断该点是否在三角形内(点在三角形边线上也认为在三角形内)?

Input

本问题有多组测试数据,每组数据一行,共8个实数,每两个实数表示一个点,前三个点表示三角形的三个点,后一个点表示需要你判断是不是在内部的点。

Output

如果再三角形内(边上也算内),输出“Yes”,否则输出“No”。

Sample Input

0.0 0.0 4.0 4.0 6.0 0.0 3.0 2.5

Sample Output

Yes
#include<bits/stdc++.h>
using namespace std;
const double PI = 4.0 * atan(1.0);
const double EPS = 1e-6;
struct point
{
	double x,y;
	point (double _x = 0,double _y = 0)
	{
		x = _x;
		y = _y;
	}
};
typedef point vect;
bool operator < (const point& a,const point& b)
{
	if(a.x!=b.x)
	return a.x<b.x;
	return a.y<b.y;
}
int dcmp(double x)
{
    return x<-EPS?-1:(x>EPS?1:0);
}
bool operator == (const point& a,const point& b)
{
    return !dcmp(a.x-b.x)&&!dcmp(a.y-b.y);
}
bool operator != (const point& a,const point& b)
{
    return dcmp(a.x-b.x)||dcmp(a.y-b.y);
}
vect operator + (vect a,vect b)
{
	return vect (a.x+b.x,a.y+b.y);
}
vect operator - (point a,point b)
{
	return vect (a.x-b.x,a.y-b.y);
}
vect operator * (vect a,double b)
{
	return vect(a.x*b,a.y*b);
}
vect operator / (vect a,double b)
{
    return vect(a.x/b,a.y/b);
}
double dot(vect a,vect b)
{
	return a.x*b.x+a.y*b.y;
}
double cross(vect a,vect b)
{
	return a.x*b.y-b.x*a.y;
}
double vect_len(vect a)
{
	return sqrt(dot(a,a));
}
vect vect_rotate(vect a,double rad)
{
    return vect(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
vect vect_normal(vect a)
{
    double L=vect_len(a);
    return vect(-a.y/L,a.x/L);
}
point a,b,c,d;
int main()
{
    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y)!=EOF)
    {
        if(dcmp(abs(cross(b-a,c-a))-abs(cross(d-a,d-b))-abs(cross(d-b,d-c))-abs(cross(d-c,d-a)))==0)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值