#include //for sqrt, abs #include "point.h" using namespace std; const point point_origin; //Return the distance between this point and the origin. double point::dist() const { const double dx = point_origin.x - x; const double dy = point_origin.y - y; return sqrt(dx * dx + dy * dy); //Pythagorean theorem } //Return the distance between points A and B. double dist(const point& A, const point& B) { const double dx = A.x - B.x; const double dy = A.y - B.y; return sqrt(dx * dx + dy * dy); } //Return the area of triangle ABC. double area(const point& A, const point& B, const point& C) { return abs(A.x * B.y + B.x * C.y + C.x * A.y - A.y * B.x - B.y * C.x - C.y * A.x) / 2; } /* Return true if the triangle ABC contains the point D, or if D is on the perimeter. Ideally area(A, B, C) would equal sum exactly, but floating point arithmetic is never exact. We return true if area(A, B, C) is within point_error of sum. */ bool contains(const point& A, const point& B, const point& C, const point& D) { const double sum = area(A, B, D) + area(B, C, D) + area(C, A, D); return abs(area(A, B, C) - sum) < point_error; }