Polar Coordinates

BlitzMax Forums/BlitzMax Programming/Polar Coordinates

Krischan(Posted 2012) [#1]
I have a problem simulating the Photoshop Polar Coordinates functions "Rectangular to Polar" and "Polar to Rectangular". It doesn't look correct and I don't know why. Can anybody help? You need two images, the "ps.png" is a screenshot from Photoshop how it should look like after.

EDIT: fixed it somehow but still buggy, changed the images to show the problem in a better way

uv.png


ps.png


My current output




Last edited 2012


Warpy(Posted 2012) [#2]
Here you go. I've explained it a tiny bit, but there's a lot of trigonometry and so on. It really needs some diagrams to fully explain, but I don't have the time.




Krischan(Posted 2012) [#3]
Thanks, that is even more complex than I thought. Your version outputs a slightly different image than PS, still with a noticable vertical line in the middle on the upper right image (the polar to rectangular), but what could be the reason for that?



Last edited 2012


Warpy(Posted 2012) [#4]
I reckon it's just differences in rounding errors or sampling from the source pixmap. The section at the top of the polar->rect image corresponds to the middle of the circle, so small errors can mean a big change in angle.


Krischan(Posted 2012) [#5]
If i take a different picture like an UV matrix it looks completely different, interesting.
Just change the image names to uv2/ps2:

uv2.png


ps2.png


Screenshot


Your algorithm creates a quadratic "tunnel" effect while photoshop creates a round "tunnel" effect. Funny.


Noobody(Posted 2012) [#6]
Like this?




Krischan(Posted 2012) [#7]
Yes, that's it. Thanks!!!


xlsior(Posted 2012) [#8]
Now... What does one actually -use- polar coordinate transforms for?


Krischan(Posted 2012) [#9]
A lot of things. In my special case I try to create a random planet texture on the fly and the polar coordinates routine is used to help delete the pinching effect at the poles if you wrap it around a sphere. If you have Photoshop (or GIMP) you can try the following:

- load a 2:1 resolution texture (ex. 512x256)
- copy the upper half part (512x128) to a new image
- stretch the image to 512x512
- apply Polar Coordinates "Rectangular to Polar"
- delete the pinch effect in the image center (Blur or Stamp Tool) manually
- apply Polar Coordinates "Polar to Rectangular"
- resize the image back to 512x128
- copy the part over the original position back
- turn the complete image 180°
- start again with the upper half part (which is the lower half part)

If done properly you'll get from the top texture the bottom texture which wraps seamless around a sphere while maintaing most of the detail in the equatorial area and has no pole pinch effect anymore.





Other useful effects include exploding effects combined with wind filter if you rotate the texture 90° CW or CCW first:



Last edited 2012


xlsior(Posted 2012) [#10]
Thanks for the nice example -- I never got into any of the 3D stuff, so didn't think about these kinds of problems/solutions.


*(Posted 2012) [#11]
@Krischan:Ya could make a brilliant Captain Blood game with that system :D