Changeset 19603 for trunk/Mars/msimreflector
- Timestamp:
- 09/02/19 21:59:18 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/msimreflector/MFresnelLens.cc
r19600 r19603 168 168 } 169 169 170 double CalcRefractiveIndex( const double &lambda)170 double CalcRefractiveIndex(double lambda) 171 171 { 172 172 // https://refractiveindex.info/?shelf=organic&book=poly(methyl_methacrylate)&page=Szczurowski … … 176 176 const double l2 = lambda*lambda; 177 177 178 const double c0 = 0.99654/(1-0.00787 /l2);179 const double c1 = 0.18964/(1-0.02191 /l2);180 const double c2 = 0.00411/(1-3.85727 /l2);178 const double c0 = 0.99654/(1-0.00787e6/l2); 179 const double c1 = 0.18964/(1-0.02191e6/l2); 180 const double c2 = 0.00411/(1-3.85727e6/l2); 181 181 182 182 return sqrt(1+c0+c1+c2); 183 183 } 184 184 185 void ApplyRefraction(MQuaternion &u, const TVector3 &n, const double &n1, const double &n2) 186 { 187 // u: incoming direction 185 bool ApplyRefraction(MQuaternion &u, const TVector3 &n, const double &n1, const double &n2) 186 { 187 // From: https://stackoverflow.com/questions/29758545/how-to-find-refraction-vector-from-incoming-vector-and-surface-normal 188 // Note that as a default u is supposed to be normalized such that z=1! 189 190 // u: incoming direction (normalized!) 188 191 // n: normal vector of surface 189 192 // n2: refractive index of new(?) medium 190 193 // n1: refractive index of old(?) medium 191 194 195 // V_refraction = r*V_incedence + (rc - sqrt(1- r^2 (1-c^2)))n 196 // r = n1/n2 197 // c = -n dot V_incedence. 198 199 // The vector should be normalized already 200 // u.NormalizeVector(); 201 192 202 const double r = n2/n1; 193 203 const double c = n*u.fVectorPart; … … 195 205 const double rc = r*c; 196 206 197 const double R = 1 - r*r + rc*rc; // = 1 - r*r *(1-c*c); 198 199 const double v = rc + sqrt(R<0 ? 0 : R); 200 201 u = r*u - n*v; 207 const double R = 1 - r*r + rc*rc; // = 1 - (r*r*(1-c*c)); 208 209 // What is this? Total reflection? 210 if (R<0) 211 return false; 212 213 const double v = rc + sqrt(R); 214 215 u.fVectorPart = r*u.fVectorPart - v*n; 216 217 return true; 202 218 } 203 219 … … 274 290 // Apply refraction at lens entrance (change directional vector) 275 291 // FIXME: Surace roughness 276 ApplyRefraction(u, norm, 1, n); 292 if (!ApplyRefraction(u, norm, 1, n)) 293 return -1; 277 294 278 295 // Propagate ray until bottom of lens … … 285 302 // Normal surface (bottom of lens) 286 303 // FIXME: Surace roughness 287 ApplyRefraction(u, TVector3(0, 0, 1), n, 1); 304 if (!ApplyRefraction(u, TVector3(0, 0, 1), n, 1)) 305 return -1; 288 306 289 307 // To make this consistent with a mirror system,
Note:
See TracChangeset
for help on using the changeset viewer.