Skip to content
Snippets Groups Projects
Commit 10656ae7 authored by Bruno Freitas Tissei's avatar Bruno Freitas Tissei
Browse files

Fix geometry_functions

parent 7e74cf4f
No related branches found
No related tags found
No related merge requests found
...@@ -6,13 +6,14 @@ template <typename T> ...@@ -6,13 +6,14 @@ template <typename T>
struct Point { struct Point {
T x, y; T x, y;
Point() {}
Point(T x, T y) : x(x), y(y) {} Point(T x, T y) : x(x), y(y) {}
Point operator+(Point p) { return Point(x+p.x, y+p.y); } Point operator+(Point p) { return Point(x+p.x, y+p.y); }
Point operator-(Point p) { return Point(x-p.x, y-p.y); } Point operator-(Point p) { return Point(x-p.x, y-p.y); }
T dot(Point p) { return (x*p.x) + (y*p.y); } T dot(Point p) { return (x*p.x) + (y*p.y); }
T cross(Point p) { return (x*p.y) - (y*p.y); } T cross(Point p) { return (x*p.y) - (y*p.x); }
// Returns angle between this and p: // Returns angle between this and p:
// atan2(y, x) is in the range [-180,180]. To get [0, 360], // atan2(y, x) is in the range [-180,180]. To get [0, 360],
...@@ -31,6 +32,13 @@ struct Point { ...@@ -31,6 +32,13 @@ struct Point {
return (cross(p) / (sqrt(dot(*this))*sqrt(p.dot(p)))); return (cross(p) / (sqrt(dot(*this))*sqrt(p.dot(p))));
} }
bool inside_triagle(Point a, Point b, Point c) {
bool c1 = (*this - b).cross(a - b) < 0;
bool c2 = (*this - c).cross(b - c) < 0;
bool c3 = (*this - a).cross(c - a) < 0;
return c1 == c2 && c1 == c3;
}
// Finds orientation of ordered triplet (a,b,c). // Finds orientation of ordered triplet (a,b,c).
// Colinear (0), Clockwise (1), Counterclockwise (2) // Colinear (0), Clockwise (1), Counterclockwise (2)
static int orientation(Point a, Point b, Point c) { static int orientation(Point a, Point b, Point c) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment