Ejemplo n.º 1
0
double line2::distance_from_segment_to_point(point2 const& point) const
{
	delta2 v = p2 - p1;
	delta2 w = point - p1;
	
	double c1 = w.dot(v);
	if(c1 <= 0)
		return point.distance(p1);
	
	double c2 = v.dot(v);
	if(c2 <= c1)
		return point.distance(p2);
	
	double b = c1 / c2;
	point2 Pb = p1 + v * b;
	return point.distance(Pb);
}
Ejemplo n.º 2
0
double line2::distance_from_line_to_point(point2 const& point) const
{
	delta2 v = p2 - p1;
	delta2 w = point - p1;
	
	double c1 = w.dot(v);
	double c2 = v.dot(v);
	double b = c1 / c2;
	
	point2 Pb = p1 + v * b;
	return point.distance(Pb);
}