From 0bbd3e55e61793cfa972aa7a12243b99f748c1ca Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 24 Feb 2011 15:41:47 +0000 Subject: [PATCH] ENH: moved pointInTet() to inside() method in tetrahedron --- .../primitiveShapes/tetrahedron/tetrahedron.H | 10 +++--- .../tetrahedron/tetrahedronI.H | 34 ++++++++++++++++++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedron.H b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedron.H index 7e55cd872c..53e92c7f66 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedron.H +++ b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedron.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -174,10 +174,10 @@ public: ) const; //- Return nearest point to p on tetrahedron - inline pointHit nearestPoint - ( - const point& p - ) const; + inline pointHit nearestPoint(const point& p) const; + + //- Return true if point is inside tetrahedron + inline bool inside(const point& pt) const; //- Return (min)containment sphere, i.e. the smallest sphere with // all points inside. Returns pointHit with: diff --git a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedronI.H b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedronI.H index 38c9eae41c..309f16ddea 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedronI.H +++ b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedronI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -380,6 +380,38 @@ inline Foam::pointHit Foam::tetrahedron::nearestPoint } +template +bool Foam::tetrahedron::inside(const point& pt) const +{ + // For robustness, assuming that the point is in the tet unless + // "definitively" shown otherwise by obtaining a positive dot + // product greater than a tolerance of SMALL. + + // The tet is defined: tet(Cc, tetBasePt, pA, pB) where the normal + // vectors and base points for the half-space planes are: + // area[0] = Sa(); + // area[1] = Sb(); + // area[2] = Sc(); + // area[3] = Sd(); + // planeBase[0] = tetBasePt = tet.b() + // planeBase[1] = ptA = tet.c() + // planeBase[2] = tetBasePt = tet.b() + // planeBase[3] = tetBasePt = tet.b() + + vector n = Sa(); + n /= (Foam::mag(n) + VSMALL); + + if (((pt - b_) & n) > SMALL) + { + return false; + } + else + { + return true; + } +} + + // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // template