If you need to warp points on a square to a disk, many people use Ken Chiu's and my code from jgt:

/* seedx, seedy is point on [0,1]^2. x, y is point on radius 1 disk */

void to_unit_disk( double seedx, double seedy, double *x, double *y )

{

double phi, r;

double a = 2*seedx - 1; >/* (a,b) is now on [-1,1]^2 */

double b = 2*seedy - 1;

if (a > -b) { /* region 1 or 2 */

if (a > b) { /* region 1, also |a| > |b| */

r = a;

phi = (M_PI/4 ) * (b/a);

}

else { /* region 2, also |b| > |a| */

phi = (M_PI/4) * (2 - (a/b));

}

}

else { /* region 3 or 4 */

if (a < b) /* region 3, also |a| >= |b|, a != 0

r = -a;

phi = (M_PI/4) * (4 + (b/a));

}

else { /* region 4, |b| >= |a|, but a==0 and b==0 could occur.

r = -b;

if (b != 0)

phi = (M_PI/4) * (6 - (a/b));

else

phi = 0;

}

}

*x = r * cos(phi);

*y = r * sin(phi);

}

Dave Cline recently sent me a neat trick that uses negative radii and I think is correct. Let me know if you try it. (cut and pasted from his mail)

Vector2 ToUnitDisk(Vector2 O) {

float phi,r;

float a = 2*O.x - 1;

float b = 2*O.y - 1;

if (a*a> b*b) { // use squares instead of absolute values

r = a;

phi = (PI/4)*(b/a);

} else {

r = b;

phi = (PI/4)*(a/b) + (PI/2);

}

return Vector2( r*cos(phi), r*sin(phi) );

}

## 11 comments:

Hey,

As is, the improved formulation leads to clumping and alignment issues when fed samples coming from a Hammersley sequence. It's easy to fix: in the second branch of the if, replace

phi = (PI/4)*(a/b) + (PI/2);

by

phi = (PI/2) - (PI/4)*(a/b);

With this modification, the new function will return the exact same results as the original jgt one.

Cheers,

Franz

Nice! Looks like we missed the case where (a==0&&b==0), so we'll have a divide-by-zero in the else section unless we add a test.

BTW, I'm using this heavily in my new BSDF sampling scheme. Very handy!

To read these Improved code for concentric map we can lear many thinks

photo retouching

To read these post Improved code for concentric map we can lear many thinks

It is very informative post so i like this post very much.

clipping paths

It is very informative post so i like this post very much.

clipping paths

You are so generous! I just love finding beautiful and artistic freebies like this. They really brighten up my day, thank you!

clipping path service provider

Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.

clipping path industry

That's a nice trick by Dave Cline! I just updated my code to use his trick. The C++ code and the resulting equations are much simpler! Here are some images showing the results:

http://squircular.blogspot.com/2015/09/circular-brady-bunch.html

This is a neat implementation and produces the same results as the jgt function (with the fix given in the first comment) with much less branching. I am just wondering why the test (a*a > b*b) is considered better than (abs(a) > abs(b)). The latter avoids two floating point multiplies and simply involves zeroing the sign bits in the binary representations for a and b.

Post a Comment