<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Conal Elliott &#187; graphics</title>
	<atom:link href="http://conal.net/blog/tag/graphics/feed" rel="self" type="application/rss+xml" />
	<link>http://conal.net/blog</link>
	<description>Inspirations &#38; experiments, mainly about denotative/functional programming in Haskell</description>
	<lastBuildDate>Thu, 25 Jul 2019 18:15:11 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.17</generator>
	<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=conal&amp;popout=1&amp;url=http%3A%2F%2Fconal.net%2Fblog%2F&amp;language=en_US&amp;category=text&amp;title=Conal+Elliott&amp;description=Inspirations+%26amp%3B+experiments%2C+mainly+about+denotative%2Ffunctional+programming+in+Haskell&amp;tags=blog" type="text/html" />
	<item>
		<title>Unifying and generalizing spatial transformation</title>
		<link>http://conal.net/blog/posts/unifying-and-generalizing-spatial-transformation</link>
		<comments>http://conal.net/blog/posts/unifying-and-generalizing-spatial-transformation#comments</comments>
		<pubDate>Sat, 14 Jan 2006 07:08:00 +0000</pubDate>
		<dc:creator><![CDATA[Conal]]></dc:creator>
				<category><![CDATA[Functional programming]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[spatial transformation]]></category>

		<guid isPermaLink="false">http://conal.net/blog/posts/unifying-and-generalizing-spatial-transformation/</guid>
		<description><![CDATA[(Edit 2008-01-14: updated formatting.) I’m trying out an idea I had a while back for unifying and generalizing different notions of spatial transformation in Pan (and spatial &#38; temporal transformation in Fran. The three notions are transforming a point, an image (which is a function from point to alpha), and an image filter (which is [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="font-style: italic;">(Edit 2008-01-14: updated formatting.)</p>

<p>I’m trying out an idea I had a while back for unifying and generalizing different notions of spatial transformation in <a href="http://conal.net/Pan">Pan</a> (and spatial &amp; temporal transformation in <a href="http://conal.net/fran">Fran</a>. The three notions are transforming a point, an image (which is a function from point to alpha), and an image filter (which is a function from image to image). A basic “transform” is a function from points to points. To transform a point, just apply the function. To transform an image, inversely transform the points fed into the image. To transform a filter, inversely transform the source image and forward transform the result image.</p>

<pre><code>type VectorE       = (DoubleE,DoubleE)
type PointE        = (DoubleE, DoubleE)
type Image c       = PointE -&gt; c
type HyperFilter c = Filter c -&gt; Filter c
</code></pre>

<p>Then for instance, scaling has these three variants:</p>

<pre><code>scaleP :: VectorE -&gt; TransformE
scaleP (sx,sy) =  (x,y) -&gt; (sx * x, sy * y)

scale :: VectorE -&gt; Filter c
scale (sx,sy) = (. scaleP (1/sx, 1/sy))

atScale :: VectorE -&gt; HyperFilter c
atScale (sx,sy) xf =
  scale (sx,sy) . xf . scale(1/sx,1/sy)
</code></pre>

<p>Hyperfilters allow some beautifully modular formulations of filters.</p>

<p>Note how in <code>scale</code> and <code>atScale</code>, I’m inverting the scaling. Exactly this pattern of inversion happens for other types of transformations as well (translation, rotation, swirl, etc). The new idea is to capture this inversion pattern once in a general rule for transforming <em>functions</em>. A type class specifies types that can be spatially transformed, which is direct for points, a do-nothing for numbers and booleans, distributes over tupling, and works similarly to <code>atScale</code> above for functions. To make this fly, I’m changing my representation of points and vectors from pairs to data types, which makes the code less succinct but is more strongly typed.</p>

<p>There’s a big catch in this plan: I only know how to handle <em>invertible</em> transformations, which rules out, e.g., tiling.</p>

<p>Here’s the class of transformable values:</p>

<pre><code>class ITrans a where
  iTrans :: ITransformE -&gt; a -&gt; a
</code></pre>

<p>and the handling of functions:</p>

<pre><code>instance (ITrans a, ITrans b) =&gt; ITrans (a-&gt;b) where
iTrans xf f = iTrans xf . f . iTrans (invIT xf)
</code></pre>

<p>The type of invertible transforms simply has a pair of transforms:</p>

<pre><code>data ITransformE =
  ITransformE { itForward  :: TransformE
              , itBackward :: TransformE }

invIT :: ITransformE -&gt; ITransformE
invIT (ITransformE forw back) = ITransformE back forw
</code></pre>

<p>Besides doing what I already do more uniformly, this generalized approach to transformation should be just the thing for <it>interactive </it>images, which may be neatly formulated again, as functions.</p>

<div align="center">
<a href="http://conal.net/Pan/Gallery/intro/medres/neal%20tiled.jpg"><img src="http://conal.net/Pan/Gallery/transparent/neal_tiled_small.png" /></a>
</div>

<div style="clear: both; padding-bottom: 0.25em;"></div>
<p><a href="http://conal.net/blog/?flattrss_redirect&amp;id=25&amp;md5=ce2396ee2d61a237590621548e2a06f1"><img src="http://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white.png" srcset="http://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white.png, http://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white@2x.png 2xhttp://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white.png, http://conal.net/blog/wp-content/plugins/flattr/img/flattr-badge-white@3x.png 3x" alt="Flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://conal.net/blog/posts/unifying-and-generalizing-spatial-transformation/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=conal&amp;popout=1&amp;url=http%3A%2F%2Fconal.net%2Fblog%2Fposts%2Funifying-and-generalizing-spatial-transformation&amp;language=en_GB&amp;category=text&amp;title=Unifying+and+generalizing+spatial+transformation&amp;description=%28Edit+2008-01-14%3A+updated+formatting.%29+I%E2%80%99m+trying+out+an+idea+I+had+a+while+back+for+unifying+and+generalizing+different+notions+of+spatial+transformation+in+Pan+%28and+spatial+%26amp%3B+temporal+transformation...&amp;tags=graphics%2Cspatial+transformation%2Cblog" type="text/html" />
	</item>
	</channel>
</rss>
