Discussion:
Transform a circle to a square?
(too old to reply)
h***@visi.com
2006-10-20 16:23:16 UTC
Permalink
Quick non-GIMP background:

I'm trying to create realistic bubbles in second life, and in doing so
I wish to map a transparency mask created from an actual bubble image
to a second life sphere object. Unfortunately the mask is circular,
while the second life texture mapping logic requires a rectangular map
or else there'd be a gap when the sphere object is actually rendered in
second life - it comes out looking like a round christmas bell instead
of a smooth sphere.

GIMP specific:

I want to transform a two dimensional circle into a two dimensional
square. Everything I wish to do within GIMP is strictly 2 dimensional
mapping - so "map to sphere" or anything like that wouldn't be useful
for what I need to do. It's the literal round peg into a square hole
metaphor.

I've looked at polar distortion and my version of GIMP (picked up a
month ago) doesn't have the "polar to rectangle" option (don't know why
and don't know if that would work but it looks like it might) and I've
browsed through all the various distortion and rendor options that come
with the standard windows self-installer.

Hope someone can help, thankyou.
h***@visi.com
2006-10-20 18:48:57 UTC
Permalink
OK, a little more looking around shows me that Mathmap would be a good
plugin to get, only problem is I run Windows XP (Linux has always been
a "one of these days" things that flat out ran out of days). Is there a
Windows executable compiled to 2.2 handy anywhere? Installing Cygwin
and compiling the source could be either a fun or a frustrating
Saturday afternoon project, but I'd like to spare the time if at all
possible. Someone posted a bunch of scripts for it recently that
included exactly the one I needed - circle to square - so no problem
finding the script for that specific transformation.

Also - are there any other graphic software packages out there that are
pretty decent at map transformations? I seem to recall PSP had that in
spades, but I lost my 5.0 copy and don't feel the ambition to spend $70
for a new copy...but it seems like the kind of thing there would be
software out there for. Would there be free/cheap adobe plugin
compatible with GIMP maybe?

Thanks again, all.
stuseven
2006-10-20 22:17:42 UTC
Permalink
I'm trying to create realistic bubbles in second life <snip>
...oh ? Interesting... err... what does that mean ? :-)
...and in doing so I wish to map a transparency mask created
from an actual bubble image to a second life sphere object <snip>
...ahhh... seems you want to borrow effects from one image, and apply
to another... OK

But frankly, as soon as I read your question, I was wondering - why not
produce
new bubbles yourself, which could be any way you liked, rather than
trying to
copy from a more limited set in another picture ?
Im quite certain Ive seen tutorials which specifically produce
[bubbles]... maybe
even in Gimp !
Unfortunately <snips interesting discussion of poster's proposed solution>
Hope someone can help, thankyou.
The most help I can be is to suggest you post one of your bubbles
pictures...
and, if possible, try to show how you'd want to use these bubbles in
the new
picture... from which, Id say many more people would understand how to
help in Gimp or otherwise.
Lyle Walsh
2006-10-21 00:27:58 UTC
Permalink
Post by h***@visi.com
I'm trying to create realistic bubbles in second life, and in doing so
I wish to map a transparency mask created from an actual bubble image
to a second life sphere object. Unfortunately the mask is circular,
while the second life texture mapping logic requires a rectangular map
or else there'd be a gap when the sphere object is actually rendered in
second life - it comes out looking like a round christmas bell instead
of a smooth sphere.
Well I'm pretty much a Gimp wanabee but I've been making textures for the
unreal engine with Gimp with good success. I'm still not clear on your
question, do you want to generate true 3d spheres, an image that looks like
a bubble or are you having trouble mapping a texture on a 3d sperical mesh?

Often an emitter with a nice alpha mapped image of a bubble can make a
random cascade of bubble like objects that can pop or fade in and out and
fall towards the ground or waft away at random. Another trick to making an
omnidirectional image would be to try to use a projector or a environmental
map cube, such as is done for lighting effects with dynamic lighting. I
would try these rather than trying to make a smooth looking spherical
skeletal mesh because you risk high polygon counts to make it look nice.
However, if that's what you want to do may I suggest that you let the game
engine do the bubble effects! Just make it using a semi transparent texture
and turn it into a material with high specularity (reflectance). If done
right these little spheres are very convincing.

I hope this helps
Lyle
h***@visi.com
2006-10-21 13:23:16 UTC
Permalink
I guess I should have made this a simple question and not included the
fooforall background to this.

How do I transform a circle to a square?

Thanks.
Lyle Walsh
2006-10-21 18:12:41 UTC
Permalink
Post by h***@visi.com
I guess I should have made this a simple question and not included the
fooforall background to this.
How do I transform a circle to a square?
Thanks.
Good question and one that mathematicians and topographers have never been
able to answer very well! Think of all the different maps you've seen of
the earth- they all are very distorted. This is why it is better to use a
uniform texture for the sphere and have the game engine render the shading
and reflectance part.

Are you trying to map a square texture onto a sphere made by the game? The
game actually makes it as a polyhedron so the application of the texture
depends on how the polyhedron is made. How many faces does it have? How
many sides do you see in top view looking down and how many sides from side
view in the game editor? The game engine doesn't use the entire texture
for the sphere. Instead it takes a triangular chunk and then takes another
triagular chunk starting at the end of the first triangle. How big a chunk
it takes and how it aligns the vertices varies with which face of the
polygon you are texturing. Also your scale is important - can the texture
go all the way around? If not it is repeated end on end and edge on edge.
So what really happens is that little or big triangles are taken out of the
texture when the triangle face points up and out of the top of the texture
when the triangle face points down. The rest of the texture is never used!
So first try an experiment - make several textures for an 8 ball from pool.
Fiddle around with where you put the white circle with the '8' in it on the
otherwise black texture. now apply them to your sphere and fiddle with
scale and offset settings to see if you can align just those 2 spots! Its
tough, I've done it. There are a lot of ways to skin this particular cat,
experiment and let us know what you learn.
Lyle
h***@visi.com
2006-10-21 18:39:18 UTC
Permalink
I'm starting to feel like a pinata here...lets not complicate things,
OK, please?

Look, the texture mapping for second life maps a square to a sphere, so
the texture I need to apply has to be a square. I've already
experimented six ways from Sunday to determine that, making my own
little coordinate grid texture with circles, squares, and angles to
help me determine how the texture gets mapped. For reference, by the
way, its the Havoc 1 engine, and no, I don't have ANY access to its
internals beyond the limited access Second Life has scripted for it. I
CANNOT do ANYTHING detailed with the game or physics engine. I just
have a simple question about how to do something in GIMP. Let's keep
focused, please?

Please, forget the game engine, please, forget triangles, vertices,
rendering, and making yet more textures. I'm happy with the textures I
have. I don't want to make anymore. This is a GIMP newsgroup, and I
have one simple question related to GIMP:

How do I transform a circle to a square using a Windows XP install of
GIMP, or other free/cheap windows software?

Thankyou.
stuseven
2006-10-21 21:07:45 UTC
Permalink
Post by h***@visi.com
I'm starting to feel like a pinata here...lets not complicate things,
OK, please?
OK - try this link
http://www.pinatas.com/

just kidding :-)

lessee... you want to transform a circle into a square... well... this
is
something Ive seen done, but not in Gimp... not even with the stretch
tool -
but, how about if you just cut a square shape out of your circle ?
Would
that work ? Gimp definitely can cut square shapes out of circular ones
-
if only most of the circle would do, try that maybe.
h***@visi.com
2006-10-24 17:13:00 UTC
Permalink
Post by stuseven
lessee... you want to transform a circle into a square... well... this
is
something Ive seen done, but not in Gimp... not even with the stretch
tool -
but, how about if you just cut a square shape out of your circle ?
Would
that work ? Gimp definitely can cut square shapes out of circular ones
-
if only most of the circle would do, try that maybe.
Where have you seen this done before? I would be very interested to
know.

As for cutting a square out, no - that wouldn't work. A lot of the
detail for a bubble is at the edges where there is a lot of
reflection/refraction/whathave you and this would be lost.

It would be really great if there were a filter that took shape "A" and
shape "B", and then transferred/stretched/squashed pixels to fit that
transformation. I think that would be idea for me, as a windows plugin.
Dave Kelly
2006-10-24 18:13:29 UTC
Permalink
Post by h***@visi.com
I'm trying to create realistic bubbles in second life, and in doing so
I wish to map a transparency mask created from an actual bubble image
Hope someone can help, thankyou.
Is this something similar to what you want?

http://www.worth1000.com/cache/contest/contestcache.asp?contest_id=12437&start=1&end=10&display=photoshop
Spamless
2006-10-24 20:26:31 UTC
Permalink
Post by h***@visi.com
I'm trying to create realistic bubbles in second life, and in doing so
I wish to map a transparency mask created from an actual bubble image
to a second life sphere object. Unfortunately the mask is circular,
while the second life texture mapping logic requires a rectangular map
or else there'd be a gap when the sphere object is actually rendered in
second life - it comes out looking like a round christmas bell instead
of a smooth sphere.
I want to transform a two dimensional circle into a two dimensional
square. Everything I wish to do within GIMP is strictly 2 dimensional
mapping - so "map to sphere" or anything like that wouldn't be useful
for what I need to do. It's the literal round peg into a square hole
metaphor.
I've looked at polar distortion and my version of GIMP (picked up a
month ago) doesn't have the "polar to rectangle" option (don't know why
and don't know if that would work but it looks like it might) and I've
browsed through all the various distortion and rendor options that come
with the standard windows self-installer.
I had posted several maps of a square to a circle. There are tons of ways to
do it. There is just one conformal way which maps the centers to each other,
the tops and the middle right edges (it involves a Schwarz-Christoffel
transformation and is used in some map/spherical projection). The code I
posted used the math-map plugin and went from square to circle (you want to
go the other way). There are polar maps, cylindrical projections, spherical
projections, etc. If you map a circle to a square and use a different map
from that used to map your object back to a circle, it will be distorted
(perhaps very distorted). As you indicate you would be using this for
another system to map to a circle, you really should know what formula that
system uses and invert it.
h***@visi.com
2006-10-24 21:17:00 UTC
Permalink
Post by Spamless
If you map a circle to a square and use a different map
from that used to map your object back to a circle, it will be distorted
(perhaps very distorted). As you indicate you would be using this for
another system to map to a circle, you really should know what formula that
system uses and invert it.
Thankyou. From what I've seen with my tests, a square is mapped to the
sphere by shrinking the image as it progresses to either pole - like a
Mercater projection where Greenland is larger than South America.
Dave Kelly
2006-10-24 22:39:49 UTC
Permalink
Post by h***@visi.com
I'm trying to create realistic bubbles in second life, and in doing so
I wish to map a transparency mask created from an actual bubble image
Look at this image;
Loading Image...

If this kind of distortion is what you are looking for then I will let
you bunch it up and herd it into a square.

Image > Filter > Distort > Curve Bend
h***@visi.com
2006-10-25 15:28:15 UTC
Permalink
Post by Dave Kelly
If this kind of distortion is what you are looking for then I will let
you bunch it up and herd it into a square.
Image > Filter > Distort > Curve Bend
Yeah, I tried that initially but it doesn't give me a lot of precision,
and I'd be looking at transforming a perfect circular selection into a
perfect square. Maybe if I could manipulate it with script-fu...

That gives me an idea, though. Is it possible to write a script that
does the following:

for each row
select all pixels in the row which are not white
stretch selection lengthwise to a fixed size
move the stretched selection so the left edge lines up with the
left image border

This would give me EXACTLY the transformation I would need. I've
latched onto a script-fu tutorial, perhaps I can do something along
those lines.

Thanks!
Dave Kelly
2006-10-25 16:08:50 UTC
Permalink
Post by h***@visi.com
That gives me an idea, though. Is it possible to write a script that
I don't write scripts so I can not answer from experience.

But one thing I have learned is that nothing is impossible until YOU
prove it impossible.

Put the script in the GIMP registry when you get it done.

Dave

Continue reading on narkive:
Loading...