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