| 1 | greg | 2.3 | { RCSid $Id: reinhartb.cal,v 2.2 2014/07/22 23:21:56 greg Exp $ } | 
| 2 | greg | 2.1 | { | 
| 3 |  |  | Compute Reinhart high-density sky patch bin (rbin) | 
| 4 |  |  |  | 
| 5 |  |  | MF              - Subdivision value (usually a power of two) | 
| 6 |  |  | Dx,Dy,Dz        - Incident direction (normalized, towards surface face) | 
| 7 | greg | 2.3 | rNx,rNy,rNz     - Surface normal (normalized, away from surface) | 
| 8 | greg | 2.1 | Ux,Uy,Uz        - Up direction vector (does not need to be normalized) | 
| 9 |  |  |  | 
| 10 |  |  | Modified from reinhart.cal | 
| 11 |  |  |  | 
| 12 |  |  | July 2014       G. Ward | 
| 13 |  |  | } | 
| 14 |  |  | { Useful factors and functions } | 
| 15 |  |  | DEGREE : PI/180; | 
| 16 | greg | 2.2 | Asin(x) : if(x-1, PI/2, if(-1-x, -PI/2, asin(x))) / DEGREE; | 
| 17 |  |  | posangle(a) : if(-a, a + 2*PI, a) / DEGREE; | 
| 18 | greg | 2.1 | Atan2(y,x) : posangle(atan2(y,x)); | 
| 19 |  |  |  | 
| 20 |  |  | { Default to Tregenza sky } | 
| 21 |  |  | MF = 1; | 
| 22 |  |  | { Default axis orientation (+Y == north) } | 
| 23 | greg | 2.3 | rNx = 0; rNy = 0; rNz = 1; | 
| 24 | greg | 2.1 | Ux = 0; Uy = 1; Uz = 0; | 
| 25 |  |  | { Compute oriented axis angles } | 
| 26 | greg | 2.3 | inc_dz = -Dx*rNx-Dy*rNy-Dz*rNz; | 
| 27 |  |  | inc_rx = -Dx*(Uy*rNz-Uz*rNy) - Dy*(Uz*rNx-Ux*rNz) - Dz*(Ux*rNy-Uy*rNx); | 
| 28 |  |  | inc_ry = -Dx*Ux-Dy*Uy-Dz*Uz - inc_dz*(rNx*Ux+rNy*Uy+rNz*Uz); | 
| 29 | greg | 2.1 |  | 
| 30 |  |  | r_alt = Asin(inc_dz)/DEGREE; | 
| 31 | greg | 2.2 | r_azi = Atan2(inc_rx,inc_ry); | 
| 32 | greg | 2.1 |  | 
| 33 |  |  | alpha = 90/(MF*7 + .5);         { Separation between rows in degrees } | 
| 34 |  |  | { Number of patches per row } | 
| 35 |  |  | tnaz(r) : select(r, 30, 30, 24, 24, 18, 12, 6); | 
| 36 |  |  | rnaz(r) = if(r-(7*MF-.5), 1, MF*tnaz(floor((r+.5)/MF) + 1)); | 
| 37 |  |  |  | 
| 38 |  |  | raccum(r) = if(r-.5, rnaz(r-1) + raccum(r-1), 0); | 
| 39 |  |  |  | 
| 40 |  |  | r_row = floor(r_alt/alpha); | 
| 41 |  |  |  | 
| 42 |  |  | r_inc = 360/rnaz(r_row); | 
| 43 |  |  |  | 
| 44 |  |  | r_azn = if(359.9999-.5*r_inc - r_azi, floor((r_azi +.5*r_inc)/r_inc), 0); | 
| 45 |  |  |  | 
| 46 |  |  | { Final bin value, -1 for "ground" } | 
| 47 |  |  | rbin = if (r_alt, raccum(r_row) + r_azn, -1); | 
| 48 |  |  |  | 
| 49 |  |  | Nrbins = raccum(7*MF+1);        { total number of bins } |