1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
/////////////////////////////////////////////////////////////
// //
// Copyright (c) 2003-2011 by The University of Queensland //
// Earth Systems Science Computational Centre (ESSCC) //
// http://www.uq.edu.au/esscc //
// //
// Primary Business: Brisbane, Queensland, Australia //
// Licensed under the Open Software License version 3.0 //
// http://www.opensource.org/licenses/osl-3.0.php //
// //
/////////////////////////////////////////////////////////////
#include "AEdge.h"
/*!
construct Edge from corner coordinates.
\param v0 first corner
\param v1 second corner
*/
AEdge::AEdge(const Vec3& v0,const Vec3& v1)
{
m_p0=v0;
m_p1=v1;
}
AEdge::~AEdge()
{}
/*!
Get min. corner of axis-aligned bounding box
*/
Vec3 AEdge::getBoundingBoxMin() const
{
return cmin(m_p0,m_p1);
}
/*!
Get max. corner of axis-aligned bounding box
*/
Vec3 AEdge::getBoundingBoxMax() const
{
return cmax(m_p0,m_p1);
}
/*!
get distance between point and closest point along edge (incl. corners)
\param p the point
*/
double AEdge::sep(const Vec3& p) const
{
double sep;
Vec3 v=m_p1-m_p0;
Vec3 vu=v.unit();
double d=((p-m_p0)*vu);
if((d>0.0)&(d*d<v.norm2())){ // closest point within edge
sep=((p-m_p0)-d*vu).norm();
} else { // closest point outside -> check corner distances
double d1=(p-m_p0).norm();
double d2=(p-m_p1).norm();
sep=(d1<d2) ? d1 : d2;
}
return sep;
}
/*!
Get perpendicular distance between point and edge.
If the closest point on the supportung line is outside the
edge, the first component of the return value is "false",
otherwise "true"
\param p the point
*/
pair<bool,double> AEdge::dist(const Vec3& p) const
{
bool is_in=false;
double dist=0.0;
Vec3 v=m_p1-m_p0;
Vec3 vu=v.unit();
double d=((p-m_p0)*vu);
if((d>0.0)&(d*d<v.norm2())){
dist=((p-m_p0)-d*vu).norm();
is_in=true;
}else{
is_in=false;
}
return make_pair(is_in,dist);
}
|