/*****************************************************************************/ /* */ /* Copyright (C) 2010-2025 M. Held, S. Huber */ /* */ /* This code is not in the public domain. All rights reserved! Please make */ /* sure to read the full copyright statement contained in "README.txt" or in */ /* the "main" file of this code, such as "main.cc". */ /* */ /*****************************************************************************/ /* */ /* Written by: Stefan Huber, Martin Held */ /* */ /* E-Mail: held@cs.sbg.ac.at */ /* Fax Mail: (+43 662) 8044-611 */ /* Voice Mail: (+43 662) 8044-6304 */ /* Snail Mail: Martin Held */ /* FB Informatik */ /* Universitaet Salzburg */ /* A-5020 Salzburg, Austria */ /* */ /*****************************************************************************/ #ifndef VRONI_GEOM_H #define VRONI_GEOM_H #include "util.h" /** Compute squared distance between two points */ inline double vroniObject::PntPntDistSq(coord pi, coord pj) { const double x = pi.x - pj.x; const double y = pi.y - pj.y; return x*x + y*y; } /** Compute distance between two points */ inline double vroniObject::PntPntDist(coord pi, coord pj) { const double x = pi.x - pj.x; const double y = pi.y - pj.y; return sqrt(x*x + y*y); } /** Compute mid point on the line (pi,pj) */ inline coord vroniObject::MidPoint(coord pi, coord pj) { coord q; q.x = (pi.x + pj.x) / 2.0; q.y = (pi.y + pj.y) / 2.0; return q; } /** Compute centroid point of the triangle (pi,pj,pk) */ inline coord vroniObject::Centroid(coord pi, coord pj, coord pk) { coord q; q.x = (pi.x + pj.x + pk.x)/3.0; q.y = (pi.y + pj.y + pk.y)/3.0; return q; } /** Build linar combination of vectors p and r by parameter t */ inline coord vroniObject::LinearComb(const coord & p, const coord & r, double_arg t_param) { coord q; q.x = p.x + t_param*(r.x-p.x); q.y = p.y + t_param*(r.y-p.y); return q; } /** Get the point q = p + t*v */ inline coord vroniObject::RayPnt(const coord & p, const coord & v, double_arg t_param) { coord q; q.x = p.x + t_param*v.x; q.y = p.y + t_param*v.y; return q; } /** Compute (signed) distance of point p to circle (c,r). Positive * values indicate that p is outside the circle (c,r). */ inline double vroniObject::PntCircleDist(const coord & c, double_arg r, const coord & p) { return PntPntDist(p, c) - r; } /** Compute absolute distance of point p tor circle (c,r) */ inline double vroniObject::AbsPntCircleDist(const coord & c, double_arg r, const coord & p) { return Abs(PntCircleDist(c, r, p)); } /** Test if point p is on circle (c,r) */ inline int vroniObject::IsPntOnCircle(const coord & c, double_arg r, const coord & p) { return eq(PntCircleDist(c,r,p), ZERO); } /** Compute the signed distance of the point p to the line given by * the equation a*x + b*y + c = 0. A positive result means that * p lies in the positive half-plane defined by the line. */ inline double vroniObject::PntLineDist(double_arg a, double_arg b, double_arg c, const coord & p) { return a*p.x + b*p.y + c; } /** Compute the absolute distance of the point p to the line given by * the equation a*x + b*y + c = 0 */ inline double vroniObject::AbsPntLineDist(double_arg a, double_arg b, double_arg c, const coord & p) { return Abs( PntLineDist(a, b, c, p)); } inline vr_bool vroniObject::IsBetweenVoronoiNodes(int e, const coord & p, double eps) { return (NodeEdgeClassificator(e, p, eps) == 0.0); } #endif