STYLE: explicitly use degrees in arcEdge coordinate system (#1015)

- safeguard against any change in the default in cylindricalCS
This commit is contained in:
Mark Olesen
2018-09-19 22:32:29 +02:00
parent 6cd953ff99
commit eda13117e4
2 changed files with 38 additions and 33 deletions

View File

@ -43,15 +43,15 @@ namespace blockEdges
Foam::cylindricalCS Foam::blockEdges::arcEdge::calcAngle() Foam::cylindricalCS Foam::blockEdges::arcEdge::calcAngle()
{ {
vector a = p2_ - p1_; const vector a = p2_ - p1_;
vector b = p3_ - p1_; const vector b = p3_ - p1_;
// find centre of arcEdge // Find centre of arcEdge
scalar asqr = a & a; const scalar asqr = a & a;
scalar bsqr = b & b; const scalar bsqr = b & b;
scalar adotb = a & b; const scalar adotb = a & b;
scalar denom = asqr*bsqr - adotb*adotb; const scalar denom = asqr*bsqr - adotb*adotb;
if (mag(denom) < VSMALL) if (mag(denom) < VSMALL)
{ {
@ -60,46 +60,46 @@ Foam::cylindricalCS Foam::blockEdges::arcEdge::calcAngle()
<< abort(FatalError); << abort(FatalError);
} }
scalar fact = 0.5*(bsqr - adotb)/denom; const scalar fact = 0.5*(bsqr - adotb)/denom;
point centre = 0.5*a + fact*((a ^ b) ^ a); point centre = 0.5*a + fact*((a ^ b) ^ a);
centre += p1_; centre += p1_;
// find position vectors w.r.t. the arcEdge centre // Find position vectors w.r.t. the arcEdge centre
vector r1(p1_ - centre); const vector r1(p1_ - centre);
vector r2(p2_ - centre); const vector r2(p2_ - centre);
vector r3(p3_ - centre); const vector r3(p3_ - centre);
// find angles // Find angle (in degrees)
angle_ = radToDeg(acos((r3 & r1)/(mag(r3) * mag(r1)))); angle_ = radToDeg(acos((r3 & r1)/(mag(r3) * mag(r1))));
// check if the vectors define an exterior or an interior arcEdge // Check if the vectors define an exterior or an interior arcEdge
if (((r1 ^ r2) & (r1 ^ r3)) < 0.0) if (((r1 ^ r2) & (r1 ^ r3)) < 0.0)
{ {
angle_ = 360.0 - angle_; angle_ = 360.0 - angle_;
} }
vector tempAxis; vector arcAxis;
if (angle_ <= 180.0) if (angle_ <= 180.0)
{ {
tempAxis = r1 ^ r3; arcAxis = r1 ^ r3;
if (mag(tempAxis)/(mag(r1)*mag(r3)) < 0.001) if (mag(arcAxis)/(mag(r1)*mag(r3)) < 0.001)
{ {
tempAxis = r1 ^ r2; arcAxis = r1 ^ r2;
} }
} }
else else
{ {
tempAxis = r3 ^ r1; arcAxis = r3 ^ r1;
} }
radius_ = mag(r3); radius_ = mag(r3);
// set up and return the local coordinate system // The corresponding local cylindrical coordinate system (degrees)
return cylindricalCS("arcEdgeCS", centre, tempAxis, r1); return cylindricalCS("arcEdgeCS", centre, arcAxis, r1, true);
} }
@ -157,10 +157,8 @@ Foam::point Foam::blockEdges::arcEdge::position(const scalar lambda) const
{ {
return p3_; return p3_;
} }
else
{ return cs_.globalPosition(vector(radius_, lambda*angle_, 0.0));
return cs_.globalPosition(vector(radius_, lambda*angle_, 0.0));
}
} }

View File

@ -55,15 +55,23 @@ class arcEdge
{ {
// Private data // Private data
// Begin, mid, end points
point p1_, p2_, p3_; point p1_, p2_, p3_;
//- The arc angle (in degrees)
scalar angle_; scalar angle_;
//- The arc radius
scalar radius_; scalar radius_;
//- The local cylindrical coordinate system (degrees)
cylindricalCS cs_; cylindricalCS cs_;
// Private Member Functions // Private Member Functions
//- Calculate the coordinate system, angle and radius //- Calculate the angle, radius and axis
// \return the coordinate system
cylindricalCS calcAngle(); cylindricalCS calcAngle();
//- No copy construct //- No copy construct
@ -85,7 +93,8 @@ public:
arcEdge arcEdge
( (
const pointField& points, const pointField& points,
const label start, const label end, const label start,
const label end,
const point& pMid const point& pMid
); );
@ -101,17 +110,15 @@ public:
//- Destructor //- Destructor
virtual ~arcEdge() virtual ~arcEdge() = default;
{}
// Member Functions // Member Functions
//- Return the point position corresponding to the curve parameter //- The point corresponding to the curve parameter [0-1]
// 0 <= lambda <= 1 point position(const scalar lambda) const;
point position(const scalar) const;
//- Return the length of the curve //- The length of the curve
scalar length() const; scalar length() const;
}; };