Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "arcEdge.H"
00027 #include <OpenFOAM/mathematicalConstants.H>
00028 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00029
00030
00031
00032 namespace Foam
00033 {
00034 defineTypeNameAndDebug(arcEdge, 0);
00035 addToRunTimeSelectionTable(curvedEdge, arcEdge, Istream);
00036 }
00037
00038
00039
00040
00041 Foam::cylindricalCS Foam::arcEdge::calcAngle()
00042 {
00043 vector a = p2_ - p1_;
00044 vector b = p3_ - p1_;
00045
00046
00047 scalar asqr = a & a;
00048 scalar bsqr = b & b;
00049 scalar adotb = a & b;
00050
00051 scalar denom = asqr*bsqr - adotb*adotb;
00052
00053 if (mag(denom) < VSMALL)
00054 {
00055 FatalErrorIn("cylindricalCS arcEdge::calcAngle()")
00056 << "Invalid arc definition - are the points co-linear? Denom ="
00057 << denom
00058 << abort(FatalError);
00059 }
00060
00061 scalar fact = 0.5*(bsqr - adotb)/denom;
00062
00063 point centre = 0.5*a + fact*((a ^ b) ^ a);
00064
00065 centre += p1_;
00066
00067
00068 vector r1(p1_ - centre);
00069 vector r2(p2_ - centre);
00070 vector r3(p3_ - centre);
00071
00072
00073 angle_ = (acos((r3 & r1)/(mag(r3) * mag(r1))))
00074 * 180.0/mathematicalConstant::pi;
00075
00076
00077 if (((r1 ^ r2) & (r1 ^ r3)) < 0.0)
00078 {
00079 angle_ = 360.0 - angle_;
00080 }
00081
00082 vector tempAxis;
00083
00084 if (angle_ <= 180.0)
00085 {
00086 tempAxis = r1 ^ r3;
00087
00088 if (mag(tempAxis)/(mag(r1)*mag(r3)) < 0.001)
00089 {
00090 tempAxis = r1 ^ r2;
00091 }
00092 }
00093 else
00094 {
00095 tempAxis = r3 ^ r1;
00096 }
00097
00098 radius_ = mag(r3);
00099
00100
00101 return cylindricalCS("arcEdgeCS", centre, tempAxis, r1);
00102 }
00103
00104
00105
00106
00107 Foam::arcEdge::arcEdge
00108 (
00109 const pointField& points,
00110 const label start,
00111 const label end,
00112 const point& pMid
00113 )
00114 :
00115 curvedEdge(points, start, end),
00116 p1_(points_[start_]),
00117 p2_(pMid),
00118 p3_(points_[end_]),
00119 cs_(calcAngle())
00120 {}
00121
00122
00123 Foam::arcEdge::arcEdge(const pointField& points, Istream& is)
00124 :
00125 curvedEdge(points, is),
00126 p1_(points_[start_]),
00127 p2_(is),
00128 p3_(points_[end_]),
00129 cs_(calcAngle())
00130 {}
00131
00132
00133
00134
00135 Foam::point Foam::arcEdge::position(const scalar lambda) const
00136 {
00137 if (lambda < 0 || lambda > 1)
00138 {
00139 FatalErrorIn("arcEdge::position(const scalar lambda) const")
00140 << "Parameter out of range, lambda = " << lambda
00141 << abort(FatalError);
00142 }
00143
00144 if (lambda < SMALL)
00145 {
00146 return p1_;
00147 }
00148 else if (lambda > 1 - SMALL)
00149 {
00150 return p3_;
00151 }
00152 else
00153 {
00154 return cs_.globalPosition(vector(radius_, lambda*angle_, 0.0));
00155 }
00156 }
00157
00158
00159 Foam::scalar Foam::arcEdge::length() const
00160 {
00161 return (angle_ * radius_) * mathematicalConstant::pi/180.0;
00162 }
00163
00164
00165