ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/cal/disk2square.cal
Revision: 1.3
Committed: Mon Jul 21 15:59:47 2014 UTC (9 years, 10 months ago) by greg
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -1 lines
State: FILE REMOVED
Log Message:
Getting close to working version of rfluxmtx

File Contents

# Content
1 { RCSid $Id: disk2square.cal,v 1.2 2011/05/20 21:23:21 greg Exp $ }
2 {
3 Convert between unit square and disk, using Shirley-Chiu mapping
4
5 5/20/2011 G. Ward
6
7 Inputs:
8 in_disk_x Input unit disk Cartesian coordiantes
9 in_disk_y center at (0,0)
10 or:
11 in_square_x Input unit square [0,1]^2
12 in_square_y
13
14 Corresponding outputs:
15 out_square_x Output unit square [0,1]^2
16 out_square_y
17 or:
18 out_disk_x Output unit disk Cartesian coordinates
19 out_disk_y center at (0,0)
20 }
21 { Compute disk position from square coordinates }
22 in_square_a = 2*in_square_x - 1;
23 in_square_b = 2*in_square_y - 1;
24
25 in_square_rgn = if(in_square_a + in_square_b,
26 if(in_square_a - in_square_b, 1, 2),
27 if(in_square_b - in_square_a, 3, 4));
28
29 out_disk_r = select(in_square_rgn, in_square_a, in_square_b,
30 -in_square_a, -in_square_b);
31
32 out_disk_phi = PI/4 * select(in_square_rgn,
33 in_square_b/in_square_a,
34 2 - in_square_a/in_square_b,
35 4 + in_square_b/in_square_a,
36 if(in_square_b*in_square_b,
37 6 - in_square_a/in_square_b,
38 0));
39
40 out_disk_x = out_disk_r*cos(out_disk_phi);
41 out_disk_y = out_disk_r*sin(out_disk_phi);
42
43 { Compute square position from disk coordinates }
44 norm_radians(p) : if(-p - PI/4, p + 2*PI, p);
45 in_disk_r = sqrt(in_disk_x*in_disk_x + in_disk_y*in_disk_y);
46 in_disk_phi = norm_radians(atan2(in_disk_y, in_disk_x));
47
48 in_disk_rgn = floor((in_disk_phi + PI/4)/(PI/2)) + 1;
49
50 out_square_a = select(in_disk_rgn,
51 in_disk_r,
52 (PI/2 - in_disk_phi)*in_disk_r/(PI/4),
53 -in_disk_r,
54 (in_disk_phi - 3*PI/2)*in_disk_r/(PI/4));
55
56 out_square_b = select(in_disk_rgn,
57 in_disk_phi*in_disk_r/(PI/4),
58 in_disk_r,
59 (PI - in_disk_phi)*in_disk_r/(PI/4),
60 -in_disk_r);
61
62 out_square_x = (out_square_a + 1)/2;
63 out_square_y = (out_square_b + 1)/2;