diff --git a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C index 86bfe9a22e..a91ed5140a 100644 --- a/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C +++ b/applications/utilities/surface/surfaceFeatureExtract/surfaceFeatureExtract.C @@ -87,73 +87,6 @@ scalar calcVertexNormalWeight } -point randomPointInPlane(const plane& p) -{ - // Perturb base point - const point& refPt = p.refPoint(); - - // ax + by + cz + d = 0 - const FixedList& planeCoeffs = p.planeCoeffs(); - - const scalar perturbX = refPt.x() + 1e-3; - const scalar perturbY = refPt.y() + 1e-3; - const scalar perturbZ = refPt.z() + 1e-3; - - if (mag(planeCoeffs[2]) < SMALL) - { - if (mag(planeCoeffs[1]) < SMALL) - { - const scalar x = - -1.0 - *( - planeCoeffs[3] - + planeCoeffs[1]*perturbY - + planeCoeffs[2]*perturbZ - )/planeCoeffs[0]; - - return point - ( - x, - perturbY, - perturbZ - ); - } - - const scalar y = - -1.0 - *( - planeCoeffs[3] - + planeCoeffs[0]*perturbX - + planeCoeffs[2]*perturbZ - )/planeCoeffs[1]; - - return point - ( - perturbX, - y, - perturbZ - ); - } - else - { - const scalar z = - -1.0 - *( - planeCoeffs[3] - + planeCoeffs[0]*perturbX - + planeCoeffs[1]*perturbY - )/planeCoeffs[2]; - - return point - ( - perturbX, - perturbY, - z - ); - } -} - - triadField calcVertexCoordSys ( const triSurface& surf, @@ -178,8 +111,8 @@ triadField calcVertexCoordSys plane p(pt, normal); - // Pick random point in plane - vector dir1 = pt - randomPointInPlane(p); + // Pick arbitrary point in plane + vector dir1 = pt - p.somePointInPlane(1e-3); dir1 /= mag(dir1); vector dir2 = dir1 ^ normal; diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C index 99539ee2c6..a5ad75c213 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -424,6 +424,34 @@ Foam::point Foam::plane::planePlaneIntersect } +Foam::point Foam::plane::somePointInPlane(const scalar dist) const +{ + // ax + by + cz + d = 0 + const FixedList coeff(planeCoeffs()); + + // Perturb the base-point + point p = refPoint() + point::uniform(dist); + + if (Foam::mag(coeff[2]) < SMALL) + { + if (Foam::mag(coeff[1]) < SMALL) + { + p[0] = -1.0*(coeff[1]*p[1] + coeff[2]*p[2] + coeff[3])/coeff[0]; + } + else + { + p[1] = -1.0*(coeff[0]*p[0] + coeff[2]*p[2] + coeff[3])/coeff[1]; + } + } + else + { + p[2] = -1.0*(coeff[0]*p[0] + coeff[1]*p[1] + coeff[3])/coeff[2]; + } + + return p; +} + + Foam::plane::side Foam::plane::sideOfPlane(const point& p) const { const scalar angle((p - point_) & normal_); @@ -464,14 +492,7 @@ void Foam::plane::writeDict(Ostream& os) const bool Foam::operator==(const plane& a, const plane& b) { - if (a.point_ == b.point_ && a.normal_ == b.normal_) - { - return true; - } - else - { - return false; - } + return (a.point_ == b.point_ && a.normal_ == b.normal_); } bool Foam::operator!=(const plane& a, const plane& b) @@ -482,9 +503,9 @@ bool Foam::operator!=(const plane& a, const plane& b) // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // -Foam::Ostream& Foam::operator<<(Ostream& os, const plane& a) +Foam::Ostream& Foam::operator<<(Ostream& os, const plane& pln) { - os << a.normal_ << token::SPACE << a.point_; + os << pln.normal_ << token::SPACE << pln.point_; return os; } diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H index 958d17d32d..a6e1d59d02 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,7 +25,7 @@ Class Foam::plane Description - Geometric class that creates a 2D plane and can return the intersection + Geometric class that creates a 3D plane and can return the intersection point between a line and the plane. SourceFiles @@ -49,13 +49,13 @@ namespace Foam // Forward declaration of friend functions and operators class plane; -bool operator==(const plane&, const plane&); -bool operator!=(const plane&, const plane&); -Ostream& operator<<(Ostream&, const plane&); +bool operator==(const plane& a, const plane& b); +bool operator!=(const plane& a, const plane& b); +Ostream& operator<<(Ostream& os, const plane& pln); /*---------------------------------------------------------------------------*\ - Class plane Declaration + Class plane Declaration \*---------------------------------------------------------------------------*/ class plane @@ -160,7 +160,7 @@ public: //- Return plane normal const vector& normal() const; - //- Return or return plane base point + //- Return plane base point const point& refPoint() const; //- Return coefficients for the @@ -196,7 +196,15 @@ public: ray planeIntersect(const plane&) const; //- Return the cutting point between this plane and two other planes - point planePlaneIntersect(const plane&, const plane&) const; + point planePlaneIntersect + ( + const plane& plane2, + const plane& plane3 + ) + const; + + //- Return a point somewhere on the plane, a distance from the base + point somePointInPlane(const scalar dist = 1e-3) const; //- Return the side of the plane that the point is on. // If the point is on the plane, then returns NORMAL. @@ -206,19 +214,20 @@ public: point mirror(const point& p) const; //- Write to dictionary - void writeDict(Ostream&) const; + void writeDict(Ostream& os) const; // friend Operators - friend bool operator==(const plane&, const plane&); - friend bool operator!=(const plane&, const plane&); + friend bool operator==(const plane& a, const plane& b); + friend bool operator!=(const plane& a, const plane& b); // IOstream Operators //- Write plane properties - friend Ostream& operator<<(Ostream&, const plane&); + friend Ostream& operator<<(Ostream& os, const plane& pln); + };