From 10656ae76311723d999e30fc7a14fb1d5e602969 Mon Sep 17 00:00:00 2001 From: Bruno Freitas Tissei <bft15@inf.ufpr.br> Date: Sat, 18 May 2019 20:42:16 -0300 Subject: [PATCH] Fix geometry_functions Signed-off-by: Bruno Freitas Tissei <bft15@inf.ufpr.br> --- algorithms/geometry/geometry_functions.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/algorithms/geometry/geometry_functions.cpp b/algorithms/geometry/geometry_functions.cpp index 2fc624c..1e2a51a 100644 --- a/algorithms/geometry/geometry_functions.cpp +++ b/algorithms/geometry/geometry_functions.cpp @@ -6,13 +6,14 @@ template <typename T> struct Point { T x, y; + Point() {} 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); } 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: // atan2(y, x) is in the range [-180,180]. To get [0, 360], @@ -31,6 +32,13 @@ struct Point { 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). // Colinear (0), Clockwise (1), Counterclockwise (2) static int orientation(Point a, Point b, Point c) { -- GitLab