ENH: plane - updated construct from components to optionally normalise the normal vector

This commit is contained in:
Andrew Heather
2016-08-11 12:14:34 +01:00
parent 8509fc3ce4
commit 582ee21ef0
2 changed files with 19 additions and 8 deletions

View File

@ -129,23 +129,29 @@ Foam::plane::plane(const vector& normalVector)
} }
Foam::plane::plane(const point& basePoint, const vector& normalVector) Foam::plane::plane
(
const point& basePoint,
const vector& normalVector,
const bool normalise
)
: :
unitVector_(normalVector), unitVector_(normalVector),
basePoint_(basePoint) basePoint_(basePoint)
{ {
scalar magUnitVector(mag(unitVector_)); scalar magSqrUnitVector(magSqr(unitVector_));
if (magUnitVector > VSMALL) if (magSqrUnitVector < VSMALL)
{
unitVector_ /= magUnitVector;
}
else
{ {
FatalErrorInFunction FatalErrorInFunction
<< "plane normal has zero length. basePoint:" << basePoint_ << "plane normal has zero length. basePoint:" << basePoint_
<< abort(FatalError); << abort(FatalError);
} }
if (normalise)
{
unitVector_ /= Foam::sqrt(magSqrUnitVector);
}
} }

View File

@ -131,7 +131,12 @@ public:
plane(const vector& normalVector); plane(const vector& normalVector);
//- Construct from normal vector and point in plane //- Construct from normal vector and point in plane
plane(const point& basePoint, const vector& normalVector); plane
(
const point& basePoint,
const vector& normalVector,
const bool normalise = true
);
//- Construct from three points in plane //- Construct from three points in plane
plane(const point& point1, const point& point2, const point& point3); plane(const point& point1, const point& point2, const point& point3);