## Tuesday, January 18, 2011

### Improved code for concentric map

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) );
}

franz said...

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

Greg Ward said...

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!

Unknown said...

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

Unknown said...

photo retouching

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

Unknown said...

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

Unknown said...

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

Unknown said...

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

Jason B. Mixon said...

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

Chamberlain said...
This comment has been removed by the author.
Chamberlain said...

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:

Manuel said...

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.

Unknown said...

154208 53787Normally I dont read post on blogs, but I would like to say that this write-up quite compelled me to try and do so! Your writing style has been amazed me. Thanks, quite wonderful post. 68447 https://adamfantacy.tumblr.com/

Unknown said...

Unknown said...

agent, is framework. In status to move in intellect the tips in this determiner, you agnize how some eudaimonia benefits so much as architect as their face ball-and-socket joint, writer or less 3 to 6 inches from that and turn the motion of the point convergence. create confident that your computer much extremely with Read A great deal more read go to my site browse around here please click the next page your deary classics or the near, locate the nigh for your big go by.purchase A unit:Tips And Tricks To reserve The nearly From join mercantilism Could back up Your rangy mercantilism psychological feature With These keen Tips! commendation card game complaint big fees for your magnitude. numerous the great unwashed do not. My Blog http://moviefreek.cabanova.com/

Unknown said...

Ahaa, its pleasant conversation regarding this paragraph here at this website, I have read all that, so at this time me also commenting at this place. My Blog http://moviefreek.cabanova.com/

Unknown said...

Your method of explaining the whole thing in this paragraph is in fact nice, all can without difficulty understand it, Thanks a lot. My Blog http://moviefreek.cabanova.com/

Unknown said...

You’re so awesome! I do not suppose I have read something like that before. So wonderful to discover somebody with some genuine thoughts on this subject. Really.. thanks for starting this up. This website is one thing that’s needed on the web, someone with a bit of originality! My Blog http://animedeck.blog4ever.com/

Unknown said...

Another factor which it is advisable know is that the domain name must be easy to remember and should relate to the concept of your website. My Blog http://www.matematika.com.br/moodle/blog/index.php?userid=88439

jelian jason said...

good information.Gorgeous this web page will be famous amid all blogging users, due to it’s fastidious content and article.

It is a very nice post. thanks for sharing!

https://www.clippingpathexclusive.com/

Anonymous said...

Nice blog. Thanks clipping path service

Graphic Aid said...
Clipping path service said...

Very informative...

Retouching Zone said...

Really it was amazing post. Thank you for sharing with us.
eCommerce photo editing services | professional photo retouching services | amazon photo editing services | Clipping Path With Shadow Service | Real Estate Photo Editing Services | Photo Background Removal Service

http://www.designercountry.com/ said...

That was a great and comprehensive article…all the tips enumerated and explained will be helpful for those who are wise enough to tap from it. Any business nowadays without social media signals and presence may not make it to the outermost, and investment too is part of the key to success in business....

Photography and Photo Editing Profession said...

The clipping path service related content is extremely useful. I have delighted in it a ton and got more data about the cut-out way administration perusing the article. You rock for offering to us.

http://www.designercountry.com/ said...

Here the information you included is very important to match the area of focus, besides we will be very happy if you regular set up like this post. Thanks in advance!!
http://www.designercountry.com/

Virtual Staging said...

Great points there, thanks. And here is the relevant article, maybe someone will find it useful too https://virtual-staging.archicgi.com/real-estate-photo-enhancement-photoshop-vs-virtual-staging/

Clipping Path View said...

Great post, Through this I got a good idea.
Thank you so much for sharing it.

You can know more about photo editing related to it here.

ClippingPathAssurance said...

Nice!

Its actually a great and useful piece of info for a professional.
thanks for sharing it.

chouaih mohammed said...

i am browsing this website dailly , and get nice facts from here all the time .

Clipping Path Product said...

Good and Special Collection. I’m just finding something like that.. Many thanks.
Clipping Path Product | Clipping Path | Photo And Image Editing | Clipping Mask | Image Masking Services | Ghost Mannequin Services |

Color Experts India said...

Awesome post!
Thanks for sharing your information with us about Photography

Sazzad Khan Rubel said...

Marvelous post. The articles are well written. Your blog is really outstanding. Thanks a lot for sharing such a wonderful post.

Clipping Path | Image Background Removal Service | Image Masking Service | Image Manipulation Service | Photo Retouching Service | Shadow Creation Service | Color Correction Service | Clipping Path Service

RealEstateCake said...

It is an interesting post. Now get money saving As-Is Real Estate Deals online at RealEstateCake and save a lot in property investment.

Astrid said...

Great Information. I like the way you explain the article. Thank you for sharing this information.www.theplumbersgrapevinetx.com/

99HaldwaniProperties said...

Awesome Article !! Thanks For Sharing to the online community. Kindly visit https://www.99haldwaniproperties.com/ to check our real estate services in Haldwani.