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