#### Archived

This topic is now archived and is closed to further replies.

# Rectangular <-> Polar coordinates

This topic is 5406 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello! I''ve got a problem: I need to convert an image from rectangular coordinates to polar and from polar to rectangular. Doing this I want to make an effect like in Photoshop: Filter->Distort->Polar coordinates. Everything will be in C++ and Windows GDI, but it does not matter. I just need an algorithm of doing this. Thank you in advance.

##### Share on other sites
well i''m not too sure about this but you will need an equation to specify how to convert from rect->polar.

So you have a rectilinier coordinate system R(x,y) and you need to convert it to a Polar coord system P(r,@), where r is the radius and @ is the angle.

I figure you can do this in many ways, one being:

r=x
@=y

Imagine this grid here in our cartesian coordinate system...
Under the polar transformation i just specified, this grid would get squished on the left hand side (so A and C are at the origin) and then B would be rotated around C, leaving us with a spider web type circle.

y/\||A------------B|  |  |   |  ||--|--|---|--||  |  |   |  ||--|--|---|--||  |  |   |  ||--|--|---|--||  |  |   |  |C------------D------->x

So yes, once you have converted to the polar coords, you probably want to plot them, you can do this using simple trig.

_x = r sin @
_y = r cos @

##### Share on other sites
This won''t create Photoshop effect

##### Share on other sites
This place has the answer somewhere. Need to read through them all:
http://astronomy.swin.edu.au/~pbourke/texture/polargrid/
http://astronomy.swin.edu.au/~pbourke/texture/spheremap/
http://astronomy.swin.edu.au/~pbourke/projection/spheretexture/
http://astronomy.swin.edu.au/~pbourke/texture/texturemapping/

##### Share on other sites
quote:
Original post by Reunion
This won''t create Photoshop effect

Maybe not the equation I used, but the method definitely would.Just choose a pt on the image to be your origin (preferably at the centre of the image) then iterate over the pixels, transforming them to their new location.

##### Share on other sites
You step through wherever you wish to store the resulting image... then map that points coordinates from polar to radial.. or visa versa. If you wish, you can use bilinear interpolation to obtain the value for that pixel (as photoshop does) or just take the nearest neighbour. The polar<->radial conversion equations are very straightforward to derive... and can be obtain from many sources, so I won''t go into it.

##### Share on other sites
ok, so a polar coordinate is (R, @) where @ is a theta.

X=Rcos@ and Y=Rsin@.

##### Share on other sites
All these are good advices but it would be good to have a piece of code. It''s usual situation when you scan the resulting image, make a back transformation, take pixels'' colour and interpolate. But I can''t make formulas, as these formulas don''t describe the whole transformations. In two words, the resulting image won''t be like in Photoshop

##### Share on other sites
Create a rectangular bitmap grid and run it through your Photoshop filter. This will show you how
Photoshop is transforming those points. Match the picture with the equation and you got it.

##### Share on other sites
All photoshops transfor does is this... rectangular to polar... it maps the image height to a radial range from 0 to half the images diagonal... and the width to the range 0..2*Pi. The origin is at the centre of the image... Since this transforms from rectangular to polar coords... it''s the inverse of the polar to rectangular conversion... so just apply it. This is EXACTLY what photoshop does, and it is VERY straightforward to make the formulae with +/-/* sin & cos. Equally, the reverse is just as straightforward... arctan and simple radius calculation. Just get a piece of paper and work it out... it''s very simple.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633709
• Total Posts
3013481
×