[plt-dev] 2htdp/image: Where oh where have my pinholes gone?
I understand that relative coordinate systems are confusing, and where
it is possible to get by without them, it simplifies matters to do so.
However, when I need them, nothing else will do.
Here is the problem. I have a picture of a guy. Let's call him
Waldo. I want to show Waldo standing in his eternally fixed pose,
overlayed with a variety of clothing and accessories. Maybe I can put
a hat on his head, a skateboard under his feet, or a leash in his hand
leading to a dog standing next to him. Whatever. I have a picture of
Waldo, I know where his head, hands, and feet are relative to his
center of mass (say, his belt buckle), and I should be able to put one
or more pictures at these points to make a composite image. Right?
I tried coding this up using htdp/image, no problem. Waldo is a blue
rectangle, his hat a green triangle, his mittens red circles, and his
boots black ellipses. Image construction was a simple matter of
overlay/xy. The result is attached in "htdp-overlay-xy.ss". The
final picture shows the blocky, blue Waldo wearing a hat and
symmetrically-placed mittens and boots.
Then I tried coding this up in 2htdp/image. Some problems. Just
"underlay" (overlay is no longer the right direction) doesn't do what
I want -- it's not relative at all, the hat and mittens and boots
would all do the same thing. The "underlay/align" function looks
promising, but it turns out that putting the hat at the "top" means
the top of the hat aligns with the top of Waldo's head. So the hat is
more like a mask. The mittens and boots, likewise, are applied to
Waldo's (visible) torso, rather than his (imaginary) limbs.
I also tried "underlay/xy", which should let me pick any offset I
want. Unfortunately, that offset is always relative to the upper left
corner of the bounding box of the resulting image. And as soon as I
put on Waldo's hat, that bounding box shifts up. So his left mitten
applies somewhere higher than Waldo's hand, more like his shoulder.
That, in turn, shifts the bounding box to the left, so the right
mitten is over his torso -- probably on top of his right ear. The
left boot, which brushes against Waldo's hip, pushes the bounding box
even further to the left, so Waldo's right boot winds up acting as a
codpiece.
The problem is that as soon as I overlay an accessory onto Waldo, I
have lost track of his center of mass; I don't know where his belt
buckle is, and as a result, where his head, hands, and feet are. Once
I add an accessory, I know where the center and edges of the new image
are, but I have lost track of my starting point. Further accessories
become harder and harder to add.
There are a couple of possible solutions here, but I don't find them
compelling, especially in a classroom scenario as an explanation of
how to build up values recursively.
One is to put Waldo on a big white background, so that his bounding
box does not change as I add accessories. This, however, requires
that I predict the largest possible accessory before I draw Waldo. It
also reintroduces the notion of a Scene, because now I do not have an
individual image composed of parts, I have one big canvas of pixels
onto which I draw everything.
The other solution that has been suggested to me is to recompute
Waldo's position after adding each accessory. This is annoying math,
however, and not always as easy as it seems. What if I draw Waldo
holding a surfboard, at an angle, in his left hand? The ends of the
surfboard might extend his bounding box a little bit (and a different
amount) in all four directions. How do I recompute that belt buckle?
For some problems, we need a relative frame of reference. I want a
pinhole, or something like it, so I can compose new images but keep
track of where I started.
I need to be able to answer, at all points: Where's Waldo?
--Carl
P.S. You may now all unleash your wrath upon me for the huge build-up
to the lame, telegraphed pun.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: htdp-overlay-xy.ss
Type: application/octet-stream
Size: 1021 bytes
Desc: not available
URL: <http://lists.racket-lang.org/dev/archive/attachments/20100112/5f31a57c/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2htdp-underlay-align.ss
Type: application/octet-stream
Size: 1067 bytes
Desc: not available
URL: <http://lists.racket-lang.org/dev/archive/attachments/20100112/5f31a57c/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2htdp-underlay-xy.ss
Type: application/octet-stream
Size: 1310 bytes
Desc: not available
URL: <http://lists.racket-lang.org/dev/archive/attachments/20100112/5f31a57c/attachment-0002.obj>