57 template <
typename Po
int,
typename LinePo
int>
60 double dx = line_pt2.x - line_pt1.x;
61 double dy = line_pt2.y - line_pt1.y;
63 double length = std::sqrt(dx*dx + dy*dy);
66 return std::abs(dy * point.
x - dx * point.
y + line_pt2.x * line_pt1.y - line_pt2.y * line_pt1.x) / length;
68 return std::sqrt(std::pow(point.
x - line_pt1.x, 2) + std::pow(point.
y - line_pt1.y, 2));
82 template <
typename Po
int,
typename LinePo
int>
85 double dx = line_end.x - line_start.x;
86 double dy = line_end.y - line_start.y;
88 double length_sqr = dx*dx + dy*dy;
93 u = ((point.
x - line_start.x) * dx + (point.
y - line_start.y) * dy) / length_sqr;
96 *is_inbetween = (u>=0 && u<=1);
99 return std::pow(point.
x-line_start.x,2) + std::pow(point.
y-line_start.y,2);
102 return std::pow(point.
x-line_end.x,2) + std::pow(point.
y-line_end.y,2);
104 return std::pow(point.
x - (line_start.x+u*dx) ,2) + std::pow(point.
y - (line_start.y+u*dy),2);
117 template <
typename Po
int,
typename LinePo
int>
132 template <
typename Po
int1,
typename Po
int2>
133 inline double norm2d(
const Point1& pt1,
const Point2& pt2)
135 return std::sqrt( std::pow(pt2.x - pt1.x, 2) + std::pow(pt2.y - pt1.y, 2) );
147 template <
typename Po
int1,
typename Po
int2>
148 inline bool isApprox2d(
const Point1& pt1,
const Point2& pt2,
double threshold)
150 return ( std::abs(pt2.x-pt1.x)<threshold && std::abs(pt2.y-pt1.y)<threshold );
double norm2d(const Point1 &pt1, const Point2 &pt2)
Calculate the distance between two 2d points.
double computeDistanceToLineSegment(const Point &point, const LinePoint &line_start, const LinePoint &line_end, bool *is_inbetween=NULL)
Calculate the distance between a point and a straight line segment.
TFSIMD_FORCE_INLINE const tfScalar & x() const
double computeDistanceToLine(const Point &point, const LinePoint &line_pt1, const LinePoint &line_pt2)
Calculate the distance between a point and a straight line (with infinite length) ...
double computeSquaredDistanceToLineSegment(const Point &point, const LinePoint &line_start, const LinePoint &line_end, bool *is_inbetween=NULL)
Calculate the squared distance between a point and a straight line segment.
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
bool isApprox2d(const Point1 &pt1, const Point2 &pt2, double threshold)
Check if two points are approximately defining the same one.