/**************************************************************************** * VCGLib o o * * Visual and Computer Graphics Library o o * * _ O _ * * Copyright(C) 2004 \/)\/ * * Visual Computing Lab /\/| * * ISTI - Italian National Research Council | * * \ * * All rights reserved. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * for more details. * * * ****************************************************************************/ /****************************************************************************/ #ifndef __VCG_DISTANCE2 #define __VCG_DISTANCE2 #include #include #include namespace vcg { /* * Computes the minimum distance between a two segments * @param[in] S0 The input segment0 * @param[in] S1 The input segment1 * return the distance between the two segments */ template ScalarType Segment2DSegment2DDistance(const vcg::Segment2 &S0, const vcg::Segment2 &S1, vcg::Point2 &p_clos0, vcg::Point2 &p_clos1) { //first test if they intersect vcg::Point2 IntPoint; if (vcg:: SegmentSegmentIntersection(S0,S1,IntPoint)) { p_clos0=IntPoint; p_clos1=IntPoint; return 0; } vcg::Point2 Pclos0=ClosestPoint(S0,S1.P0()); vcg::Point2 Pclos1=ClosestPoint(S0,S1.P1()); vcg::Point2 Pclos2=ClosestPoint(S1,S0.P0()); vcg::Point2 Pclos3=ClosestPoint(S1,S0.P1()); ScalarType d0=(Pclos0-S1.P0()).Norm(); ScalarType d1=(Pclos1-S1.P1()).Norm(); ScalarType d2=(Pclos2-S0.P0()).Norm(); ScalarType d3=(Pclos3-S0.P1()).Norm(); //then return the minimuim distance if ((d0