Ignore:
Timestamp:
12/12/06 17:25:53 (18 years ago)
Author:
bittner
Message:

mixture distribution initial coding

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.cpp

    r1867 r1883  
    228228} 
    229229 
    230  
    231230Vector3 
    232231CosineRandomVector(const Vector3 &normal) 
    233232{ 
    234   //  float r1 = RandomValue(0.0f, 1.0f); 
    235   //  float r2 = RandomValue(0.0f, 1.0f); 
    236233  float r1, r2; 
    237234   
    238 #if USE_HALTON  
    239   halton2.GetNext(r1, r2); 
    240 #else 
    241    r1 = RandomValue(0.0f, 1.0f); 
    242    r2 = RandomValue(0.0f, 1.0f); 
    243 #endif 
    244  
    245    float theta = 2.0f*M_PI*r2; 
    246    float radius = sqrt(r1); 
    247    float x = radius*sin(theta); 
    248    float z = radius*cos(theta); 
    249    float y = sqrt(1.0f - x*x - z*z); 
    250  
     235  r1 = RandomValue(0.0f, 1.0f); 
     236  r2 = RandomValue(0.0f, 1.0f); 
     237   
     238  return CosineRandomVector(r1, r2, normal); 
     239} 
     240 
     241Vector3 
     242CosineRandomVector(const float r1, 
     243                                   const float r2, 
     244                                   const Vector3 &normal) 
     245{ 
     246  float theta = 2.0f*M_PI*r2; 
     247  float radius = sqrt(r1); 
     248  float x = radius*sin(theta); 
     249  float z = radius*cos(theta); 
     250  float y = sqrt(1.0f - x*x - z*z); 
     251   
     252  Vector3 dir(x, 
     253                          y, 
     254                          z); 
     255   
     256  //  return Normalize(dir); 
    251257    
    252    Vector3 dir(x, 
    253                            y, 
    254                            z); 
    255     
    256     
    257    //  return Normalize(dir); 
    258     
    259    Matrix4x4 m = RotationVectorsMatrix( 
    260                                                                            normal, 
    261                                                                            Vector3(0,1,0)); 
    262    Matrix4x4 mi = Invert(m); 
    263    m = m*RotationVectorsMatrix( 
    264                                                            Vector3(0,1,0), 
    265                                                            Normalize(dir))*mi; 
    266    
    267    return TransformNormal(m, normal); 
     258  Matrix4x4 m = RotationVectorsMatrix( 
     259                                                                          normal, 
     260                                                                          Vector3(0,1,0) 
     261                                                                          ); 
     262  Matrix4x4 mi = Invert(m); 
     263  m = m*RotationVectorsMatrix( 
     264                                                          Vector3(0,1,0), 
     265                                                          Normalize(dir))*mi; 
     266   
     267  return TransformNormal(m, normal); 
    268268} 
    269269 
Note: See TracChangeset for help on using the changeset viewer.