vcglib/vcg/space/intersection2.h

68 lines
2.9 KiB
C
Raw Normal View History

2004-08-04 22:53:54 +02:00
/****************************************************************************
* 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 __VCGLIB_INTERSECTION_2
#define __VCGLIB_INTERSECTION_2
#include <vcg/space/point2.h>
#include <vcg/space/triangle2.h>
2004-10-13 14:45:51 +02:00
namespace vcg {
2004-08-04 22:53:54 +02:00
/** \addtogroup space */
/*@{*/
/**
Function computing the intersection between couple of geometric primitives in
2 dimension
*/
/// return true if the algle is convex (right rotation)
template<class SCALAR_TYPE>
inline bool Convex(const Point2<SCALAR_TYPE> & p0,const Point2<SCALAR_TYPE> & p1,const Point2<SCALAR_TYPE> & p2)
{
return (((p0-p1)^(p2-p1))<=0);
}
/// interseciton between point and triangle
template<class SCALAR_TYPE>
inline bool Intersection( const Triangle2<SCALAR_TYPE> & t,const Point2<SCALAR_TYPE> & p)
{
Point2<SCALAR_TYPE> p0=t.P0(0);
Point2<SCALAR_TYPE> p1=t.P0(1);
Point2<SCALAR_TYPE> p2=t.P0(2);
if (!Convex(p0,p1,p2))
std::swap<Point2<SCALAR_TYPE> >(p1,p2);
return((Convex(p,p0,p1))&&(Convex(p,p1,p2))&&(Convex(p,p2,p0)));
//return((Convex(p,p0,p1))&&(Convex(p,p1,p2))&&(Convex(p,p2,p0)));
}
2004-10-13 14:45:51 +02:00
/*@}*/
2004-08-04 22:53:54 +02:00
} // end namespace
#endif