判断两直线是否平行
// 判断两直线是否平行
const bool Geo::is_parallel(const Point &point0, const Point &point1, const Point &point2, const Point &point3)
{
if (point0.x == point1.x && point2.x == point3.x)
{
return true;
}
else
{
return ((point0.y - point1.y) / (point0.x - point1.x)) == ((point2.y - point3.y) / (point2.x - point3.x));
}
}
// 判断两直线是否平行
const bool Geo::is_parallel(const Line &line0, const Line &line1)
{
return Geo::is_parallel(line0.front(), line0.back(), line1.front(), line1.back());
}
判断多边形是否为矩形
// 判断多边形是否为矩形
const bool Geo::is_Rectangle(const Polygon &polygon)
{
Geo::Polygon points(polygon);
if (polygon.size() > 5)
{
for (size_t i = 2, count = polygon.size(); i < count; ++i)
{
if (Geo::is_inside(points[i - 1], points[i - 2], points[i]))
{
points.remove(--i);
--count;
}
}
}
if (polygon.size() != 5)
{
return false;
}
if (Geo::distance(points[0], points[1]) == Geo::distance(points[2], points[3]) &&
Geo::distance(points[1], points[2]) == Geo::distance(points[0], points[3]))
{
const Geo::Point vec0 = points[0] - points[1], vec1 = points[2] - points[1];
return std::abs(vec0.x * vec1.x + vec0.y * vec1.y) == 0;
}
else
{
return false;
}
}
判断点是否在直线左侧
// 判断点是否在直线的左侧
const bool Geo::is_on_left(const Point &point, const Point &start, const Point &end)
{
return (end.x - start.x) * (point.y - start.y) - (end.y - start.y) * (point.x - end.x) > 0;
}