<?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>cat brain.log &#124; less &#187; earth</title>
	<atom:link href="http://log.largevoid.com/tag/earth/feed/" rel="self" type="application/rss+xml" />
	<link>http://log.largevoid.com</link>
	<description>Getting it down on `paper`</description>
	<lastBuildDate>Mon, 06 Feb 2012 06:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using Log Math to Solve Iterative Problems</title>
		<link>http://log.largevoid.com/2009/11/using-log-math-to-solve-iterative-problems/</link>
		<comments>http://log.largevoid.com/2009/11/using-log-math-to-solve-iterative-problems/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 01:09:36 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
				<category><![CDATA[Reference]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[earth]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[mercator]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[projection]]></category>
		<category><![CDATA[viewport]]></category>
		<category><![CDATA[zoom]]></category>

		<guid isPermaLink="false">http://log.largevoid.com/?p=134</guid>
		<description><![CDATA[Premise: You have a map of infinite resolution, but finite viewing space. You have points on that map that have a fixed foot print. Question: How much do you need to zoom before the points are clearly distinguishable? Let us arbitrarily define the criteria for distinguishability as an icon of 25 pixels in size. This [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Premise</strong>: You have a map of infinite resolution, but finite viewing space.  You have points on that map that have a fixed foot print.</p>
<p><strong>Question</strong>: How much do you need to zoom before the points are clearly distinguishable?</p>
<p>Let us arbitrarily define the <em>criteria for distinguishability</em> as an icon of 25 pixels in size.  This icon, it can be said, has a radius of 13 pixels.  In reality, icon size is a function of your viewport&#8217;s size.  I leave that up to you to calculate.</p>
<p>Let us define the <em>scale of the map</em> as the absolute width of the map (in map units) divided by the width of the view port.  As an example, let&#8217;s use the Earth&#8217;s longitude range: -180 to +180 degrees, but in a global Mercator projection.  The coordinate range of longitude for this map is [-20037508,+20037508) meters.  Our viewport has a range of [0,255] pixels (viewport units).  The scale of this map in this viewport is (2*20037508)/256.  Be careful not to double-count +20037508, as -20037508 = +20037508 and would yield an improper scale.  The viewport size is an integer and does not wrap; there are no fractions of a pixel in a viewport.</p>
<p>We shall now define a <em>target scale</em>.  The target scale is the desired scale of the map that allows our icons to become viewable.  Our example will use buildings having a foot print of 300 meters (map units) in width and depth.  Our target scale, therefore, is 300/25 = 12 meters per pixel.</p>
<p><strong>Question</strong>: How much do we need to zoom in before our buildings are distinguishable?</p>
<p><strong>Implementation</strong> 1 (naive, iterative):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> zoomLevel<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$maprange</span><span style="color: #339933;">,</span> <span style="color: #000088;">$viewport</span><span style="color: #339933;">,</span> <span style="color: #000088;">$distFactor</span><span style="color: #339933;">=</span><span style="color:#800080;">0.10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$zoomFactor</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// $viewport = 256;</span>
  <span style="color: #666666; font-style: italic;">// $maprange = 2*M_PI*6378137;</span>
  <span style="color: #000088;">$scale</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$maprange</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$viewport</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// 10% of viewport required to distinguish an icon.</span>
  <span style="color: #000088;">$target</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$distFactor</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$viewport</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$zoom</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$scale</span> <span style="color: #339933;">&gt;</span> <span style="color: #000088;">$target</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$zoom</span> <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$scale</span> <span style="color: #339933;">/=</span> <span style="color: #000088;">$zoomFactor</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$zoom</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>Implementations</strong> 2, 3 and 4:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> zoomLevel<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$maprange</span><span style="color: #339933;">,</span> <span style="color: #000088;">$viewport</span><span style="color: #339933;">,</span> <span style="color: #000088;">$distFactor</span><span style="color: #339933;">=</span><span style="color:#800080;">0.10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$zoomFactor</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$scale</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$maprange</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$viewport</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$target</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$distFactor</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$viewport</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// naive log</span>
  <span style="color: #b1b100;">return</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$scale</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$zoomFactor</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$zoomFactor</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// commutative log</span>
  <span style="color: #b1b100;">return</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$scale</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$zoomFactor</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// subtraction property of logs (best implementation)</span>
  <span style="color: #b1b100;">return</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$scale</span><span style="color: #339933;">/</span><span style="color: #000088;">$target</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$zoomFactor</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://log.largevoid.com/2009/11/using-log-math-to-solve-iterative-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  log.largevoid.com/tag/earth/feed/ ) in 0.47306 seconds, on Feb 8th, 2012 at 4:11 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 8th, 2012 at 5:11 am UTC -->
