ps: 打计算几何模板的时候一定要细心,没把握时要多检查,很多时候就是打模板出错。
#include<cmath>
#define max(a, b)((a)>(b)?(a):(b))
#define min(a, b)((a)<(b)?(a):(b))
const double eps = 1e-8;
structPoint{
};
structLine{
};
structSegment{
};
structTriangle{
};
structRectangle{
};
structPolygon{
};
structCircle{
};
double mydis(Point p1, Point p2){ } 则判断PP1与PP2的点积结果的符号,用u·v表示。通用公式:|u||v|cos<u,v>。 * 由两点求边的方程,运用(x2-x1)(y-y1) = (y2-y1)(x-x1)。 Line getLine(Point p1, Point p2){ * 判断两直线是否平行。 bool parallel(Line l1, Linel2){ * 判断两直线是否重合。 bool lineEqual(Line l1, Linel2){ * 求两相交直线的交点。 Point getIntersect(Line l1, Line l2){ * 知道直线上两点p1p2,判断直线与线段是否相交,含顶点。 double mult(Point sp, Point ep, Point op){ bool isIntersected(Point p1, Point p2, Point s,Point e){ * 1判断两线段是否相交,含顶点。 double mult(Point sp, Point ep, Point op){ bool isIntersected(Point s1, Point e1, Point s2,Point e2){ * 2判断两线段是否相交,不含顶点。 int dblcmp(double r){ double dot(double x1, double y1, double x2, double y2){ double cross(Point a, Point b, Point c){ bool isIntersected(Point a, Point b, Point c, Point d){ * 求两条不重复相交线段的交点。 Point getInter(Point s1, Point e1, Point s2, Point e2){ * 1求凸包:1.求之前判断是否够3个顶点,2.求之后判断是否为一条直线:top <3,3.求后记得用res[]? bool cmp(Point &a, Point&b){ bool void } * 求多边形面积,凹凸都可以,p[]必为按照逆时针方向存储。 double area(int n, Point p[]) {
„ 若PP1•PP2 < 0,则P在P1P2内部
„ 若PP1•PP2 > 0,则P在P1P2外部
„ 若PP1•PP2 = 0,则P与P1或P2重合
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}