Changeset 19637 for trunk/Mars


Ignore:
Timestamp:
09/15/19 14:21:31 (5 years ago)
Author:
tbretz
Message:
Added the possibility to turn off Fresnel reflection and added some comments.
Location:
trunk/Mars/msimreflector
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/msimreflector/MOptics.cc

    r19629 r19637  
    168168        return false;
    169169
    170     u.fRealPart *= n1/n2;
     170    u.fRealPart *= n2/n1;
    171171    return true;
    172172}
     
    258258// n1 is always the medium where the photon comes from.
    259259//
    260 // Uses Fresnel's equation for calculating reflection
     260// Uses Fresnel's equation for calculating reflection. Total internal
     261// reflection above the critical angle will always take place. Fresnel
     262// reflection will only be calculated if 'fresnel' is set to true (default).
     263// For Fresnel reflection, a random number is produced according to the
     264// calculated reflectivity to decide whether the ray is reflected or
     265// refracted.
     266//
    261267//
    262268// The direction of the normal vector does not matter, it is automatically
     
    276282//  4 refraction applied
    277283//
    278 int MOptics::ApplyTransition(TVector3 &u, TVector3 n, double n1, double n2)
     284int MOptics::ApplyTransition(TVector3 &u, TVector3 n, double n1, double n2, bool fresnel)
    279285{
    280286    if (n1==n2)
     
    309315    const double reflectivity = (Rt*Rt + Rp*Rp)/2;
    310316
    311     if (gRandom->Uniform()<reflectivity)
     317    if (fresnel && gRandom->Uniform()<reflectivity)
    312318    {
    313319        // ----- Case of reflection ----
     
    327333    const int rc = ApplyTransitionFast(u.fVectorPart, n, n1, n2);
    328334    if (rc>=3)
    329         u.fRealPart *= n1/n2;
     335        u.fRealPart *= n2/n1;
    330336    return rc;
    331337}
    332338
    333 int MOptics::ApplyTransition(MQuaternion &u, const TVector3 &n, double n1, double n2)
    334 {
    335     const int rc = ApplyTransition(u.fVectorPart, n, n1, n2);
     339int MOptics::ApplyTransition(MQuaternion &u, const TVector3 &n, double n1, double n2, bool fresnel)
     340{
     341    const int rc = ApplyTransition(u.fVectorPart, n, n1, n2, fresnel);
    336342    if (rc>=3)
    337         u.fRealPart *= n1/n2;
     343        u.fRealPart *= n2/n1;
    338344    return rc;
    339345}
  • trunk/Mars/msimreflector/MOptics.h

    r19629 r19637  
    3535    static int ApplyTransitionFast(MQuaternion &u, const TVector3 &n, double n1, double n2);
    3636
    37     static int ApplyTransition(TVector3 &u, TVector3 n, double n1, double n2);
    38     static int ApplyTransition(MQuaternion &u, const TVector3 &n, double n1, double n2);
     37    static int ApplyTransition(TVector3 &u, TVector3 n, double n1, double n2, bool fresnel=true);
     38    static int ApplyTransition(MQuaternion &u, const TVector3 &n, double n1, double n2, bool fresnel=true);
    3939
    4040    ClassDef(MOptics, 1) // Base class for optics (reflector, lens)
Note: See TracChangeset for help on using the changeset viewer.