25 lines
696 B
C
25 lines
696 B
C
#pragma once
|
|
#ifndef UTILITY_H
|
|
|
|
static float sign(float x, float y, float x1, float y1, float x2, float y2)
|
|
{
|
|
return (x - x2) * (y1 - y2) - (x1 - x2) * (y - y2);
|
|
}
|
|
|
|
static float sign (const Point &pt, const Point &p1, const Point &p2)
|
|
{
|
|
return (pt.x() - p2.x()) * (p1.y() - p2.y()) - (p1.x() - p2.x()) * (pt.y() - p2.y());
|
|
}
|
|
|
|
static bool IsPointInTriangle(const Point &pt, const Point &p1, const Point &p2, const Point &p3)
|
|
{
|
|
float d1 = sign(pt, p1, p2);
|
|
float d2 = sign(pt, p2, p3);
|
|
float d3 = sign(pt, p3, p1);
|
|
|
|
bool has_neg = (d1 < 0) || (d2 < 0) || (d3 < 0);
|
|
bool has_pos = (d1 > 0) || (d2 > 0) || (d3 > 0);
|
|
|
|
return !(has_neg && has_pos);
|
|
}
|
|
#endif // UTILITY_H
|