判断点在直线哪侧
int cross(Point a,Point b,Point p)
{
return (b.x-a.x)*(p.y-a.y)-(p.x-a.x)*(b.y-a.y);
}
三角形相关
int sgn(double x)
{
if (fabs(x) < eps)
return 0;
if (x < 0)
return -1;
else
return 1;
}
struct Point
{
double x, y;
Point() {}
Point(double _x, double _y)
{
x = _x;
y = _y;
}
void input()
{
scanf("%lf%lf", &x, &y);
}
bool operator==(Point b) const
{
return sgn(x - b.x) == 0 && sgn(y - b.y) == 0;
}
Point operator-(const Point &b) const
{
return Point(x - b.x, y - b.y);
}
//叉积
double operator^(const Point &b) const
{
return x * b.y - y * b.x;
}
//点积
double operator*(const Point &b) const
{
return x * b.x + y * b.y;
}
//返回两点的距离
double dis(Point p)
{
return hypot(x - p.x, y - p.y);//ypot(a,b)=sqrt(a*a+b*b)
}
Point operator+(const Point &b) const
{
return Point(x + b.x, y + b.y);
}
Point operator*(const double &k) const
{
return Point(x * k, y * k);
}
Point operator/(const double &k) const
{
return Point(x / k, y / k);
}
};
struct Line
{
Point s, e;
Line() {}
Line(Point _s, Point _e)
{
s = _s;
e = _e;
}
// 点在线段上的判断
bool pointonseg(Point p)
{
return sgn((p - s) ^ (e - s)) == 0 && sgn((p - s) * (p - e)) <= 0;
}
// 求两直线的交点
Point crosspoint(Line v)
{
double a1 = (v.e - v.s) ^ (s - v.s);
double a2 = (v.e - v.s) ^ (e - v.s);
return Point((s.x * a2 - e.x * a1) / (a2 - a1), (s.y * a2 - e.y * a1) / (a2 - a1));
}
};
// 求点a和点b的中点
Point get_mid(Point a, Point b)
{
return (a + b) * 0.5;
}
// 根据三个点计算三角形面积
double area(Point a, Point b, Point c)
{
return fabs((b - a) ^ (c - a) * 0.5);
}
int main()
{
//用法
Point a, b, c, p;
Line ab, ac, bc;
a.input(), p.input();
ab = Line(a, b);
a.dis(p);
double s,s2;
ll flag = sgn(s - s2);
if (flag == 0)
break;
if (flag == 1)
r = mid;
else
l = mid;
}
海伦公式求三角形面积
double get_s(double x1, double y1, double x2, double y2, double x3, double y3)
{
double ab = dis(x1, y1, x2, y2);
double ac = dis(x1, y1, x3, y3);
double bc = dis(x2, y2, x3, y3);
double p = (ab + bc + ac) / 2.0;
return sqrt(p * (p - ab) * (p - ac) * (p - bc));
}