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 #include "face.H"
00030 #include <OpenFOAM/pointHit.H>
00031 #include <OpenFOAM/triPointRef.H>
00032 #include <OpenFOAM/line.H>
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 Foam::pointHit Foam::face::ray
00046 (
00047 const point& p,
00048 const vector& n,
00049 const pointField& meshPoints,
00050 const intersection::algorithm alg,
00051 const intersection::direction dir
00052 ) const
00053 {
00054 point ctr = Foam::average(points(meshPoints));
00055
00056 scalar nearestHitDist = GREAT;
00057
00058 scalar nearestMissDist = GREAT;
00059 bool eligible = false;
00060
00061
00062 pointHit nearest(p);
00063
00064 const labelList& f = *this;
00065
00066 label nPoints = size();
00067
00068 point nextPoint = ctr;
00069
00070 for (label pI = 0; pI < nPoints; pI++)
00071 {
00072 nextPoint = meshPoints[f[fcIndex(pI)]];
00073
00074
00075
00076 pointHit curHit = triPointRef
00077 (
00078 meshPoints[f[pI]],
00079 nextPoint,
00080 ctr
00081 ).ray(p, n, alg, dir);
00082
00083 if (curHit.hit())
00084 {
00085 if (Foam::mag(curHit.distance()) < Foam::mag(nearestHitDist))
00086 {
00087 nearestHitDist = curHit.distance();
00088 nearest.setHit();
00089 nearest.setPoint(curHit.hitPoint());
00090 }
00091 }
00092 else if (!nearest.hit())
00093 {
00094
00095 if (curHit.eligibleMiss())
00096 {
00097 eligible = true;
00098
00099
00100
00101 scalar missDist =
00102 Foam::mag
00103 (
00104 p + curHit.distance()*n
00105 - curHit.missPoint()
00106 );
00107
00108 if (missDist < nearestMissDist)
00109 {
00110 nearestMissDist = missDist;
00111 nearest.setDistance(curHit.distance());
00112 nearest.setPoint(curHit.missPoint());
00113 }
00114 }
00115 }
00116 }
00117
00118 if (nearest.hit())
00119 {
00120 nearest.setDistance(nearestHitDist);
00121 }
00122 else
00123 {
00124
00125 nearest.setMiss(eligible);
00126 }
00127
00128 return nearest;
00129 }
00130
00131
00132 Foam::pointHit Foam::face::intersection
00133 (
00134 const point& p,
00135 const vector& q,
00136 const point& ctr,
00137 const pointField& meshPoints,
00138 const intersection::algorithm alg,
00139 const scalar tol
00140 ) const
00141 {
00142 scalar nearestHitDist = VGREAT;
00143
00144
00145 pointHit nearest(p);
00146
00147 const labelList& f = *this;
00148
00149 forAll(f, pI)
00150 {
00151
00152 pointHit curHit = triPointRef
00153 (
00154 meshPoints[f[pI]],
00155 meshPoints[f[fcIndex(pI)]],
00156 ctr
00157 ).intersection(p, q, alg, tol);
00158
00159 if (curHit.hit())
00160 {
00161 if (Foam::mag(curHit.distance()) < nearestHitDist)
00162 {
00163 nearestHitDist = Foam::mag(curHit.distance());
00164 nearest.setHit();
00165 nearest.setPoint(curHit.hitPoint());
00166 }
00167 }
00168 }
00169
00170 if (nearest.hit())
00171 {
00172 nearest.setDistance(nearestHitDist);
00173 }
00174
00175 return nearest;
00176 }
00177
00178
00179 Foam::pointHit Foam::face::nearestPoint
00180 (
00181 const point& p,
00182 const pointField& meshPoints
00183 ) const
00184 {
00185 const face& f = *this;
00186 point ctr = centre(meshPoints);
00187
00188
00189 pointHit nearest(p);
00190
00191 label nPoints = f.size();
00192
00193 point nextPoint = ctr;
00194
00195 for (label pI = 0; pI < nPoints; pI++)
00196 {
00197 nextPoint = meshPoints[f[fcIndex(pI)]];
00198
00199
00200
00201 triPointRef tri
00202 (
00203 meshPoints[f[pI]],
00204 nextPoint,
00205 ctr
00206 );
00207
00208 pointHit curHit = tri.nearestPoint(p);
00209
00210 if (Foam::mag(curHit.distance()) < Foam::mag(nearest.distance()))
00211 {
00212 nearest.setDistance(curHit.distance());
00213
00214 if (curHit.hit())
00215 {
00216 nearest.setHit();
00217 nearest.setPoint(curHit.hitPoint());
00218 }
00219 else
00220 {
00221
00222 nearest.setMiss(true);
00223 nearest.setPoint(curHit.missPoint());
00224 }
00225 }
00226 }
00227
00228 return nearest;
00229 }
00230
00231
00232