<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[The Osmosian Order of Plain English Programmers Welcomes You]]></provider_name><provider_url><![CDATA[http://osmosianplainenglishprogramming.blog]]></provider_url><author_name><![CDATA[gerryrzeppa]]></author_name><author_url><![CDATA[https://osmosianplainenglishprogramming.blog/author/gerryrzeppa/]]></author_url><title><![CDATA[Plain English Programming — Smoothing&nbsp;Polygons]]></title><type><![CDATA[link]]></type><html><![CDATA[<header class="entry-header">
<h1 class="entry-title"></h1>
</header>
<div class="entry-content">
<p>This is how we define a polygon in Plain English:</p>
<p><span style="color:#00ccff;">A polygon is a thing with some vertices.</span></p>
<p>And this is how we define a vertex:</p>
<p><span style="color:#00ccff;">A vertex is a thing with an x coord, a y coord, and a spot at the x.</span></p>
<p>The part that says “and a spot at the x” overlays the vertex’s x and y coordinates with a spot, just for convenience.</p>
<p>Now this is a page I whipped up in Plain English’s built-in WYSIWYG page editor to describe how we smooth polygons:</p>
<p><img loading="lazy" class="alignnone size-large wp-image-318487" src="https://cdncontribute.geeksforgeeks.org/wp-content/uploads/how-to-smooth-a-polygon-1-1024x819.png" alt="" width="665" height="532" /></p>
<p>And these are the Plain English sentences we use to actually do the job:</p>
<p><span style="color:#00ccff;">To smooth a polygon:</span><br />
<span style="color:#00ccff;"> If the polygon is nil, exit.</span><br />
<span style="color:#00ccff;"> If the polygon&#8217;s vertices&#8217; count is less than 3, exit.</span><br />
<span style="color:#00ccff;"> If the polygon is closed,</span><br />
<span style="color:#00ccff;"> append the polygon&#8217;s first vertex&#8217;s next&#8217;s spot to the polygon; set a flag.</span><br />
<span style="color:#00ccff;"> Put the polygon&#8217;s first vertex into a left vertex.</span><br />
<span style="color:#00ccff;"> Loop.</span><br />
<span style="color:#00ccff;"> If the left vertex&#8217;s next is nil, break.</span><br />
<span style="color:#00ccff;"> Put the left vertex&#8217;s next into a right vertex.</span><br />
<span style="color:#00ccff;"> Get a center spot given the left vertex&#8217;s spot and the right vertex&#8217;s spot.</span><br />
<span style="color:#00ccff;"> Insert the center into the polygon after the left vertex.</span><br />
<span style="color:#00ccff;"> Put the left vertex&#8217;s next into a new vertex.</span><br />
<span style="color:#00ccff;"> If the left vertex&#8217;s previous is nil, put the right vertex into the left vertex; repeat.</span><br />
<span style="color:#00ccff;"> Get another center spot given the left vertex&#8217;s previous&#8217; spot and the new vertex&#8217;s spot.</span><br />
<span style="color:#00ccff;"> Get a difference between the other center and the left vertex&#8217;s spot.</span><br />
<span style="color:#00ccff;"> Divide the difference by 2.</span><br />
<span style="color:#00ccff;"> Add the difference to the left vertex&#8217;s spot.</span><br />
<span style="color:#00ccff;"> Put the right vertex into the left vertex.</span><br />
<span style="color:#00ccff;"> Repeat.</span><br />
<span style="color:#00ccff;"> If the flag is not set, exit.</span><br />
<span style="color:#00ccff;"> Destroy the polygon&#8217;s first vertex given the polygon.</span><br />
<span style="color:#00ccff;"> Destroy the polygon&#8217;s last vertex given the polygon.</span></p>
<p>It’s a little more complicated than the picturesque explanation because it has to deal with both open and closed polygons, and with left over vertices when the total number of vertices isn’t evenly divisible by three.</p>
<p>Here are some sample polygons, shown left-to-right (a) in their original state, (b) smoothed once, (c) smoothed twice, and (d) smoothed three times:</p>
<p><img loading="lazy" class="alignnone size-large wp-image-318452" src="https://cdncontribute.geeksforgeeks.org/wp-content/uploads/sample-smoothings-1024x819.png" alt="" width="665" height="532" /></p>
<p>The first example shows that you <em>can </em>put a square peg in a round hole, if you smooth it up first. The red line in the final example shows how smoothing can be used to fit a curve to an irregular dataset.</p>
<p>And that, folks, is…</p>
<p><img loading="lazy" class="alignnone size-large wp-image-318454" src="https://cdncontribute.geeksforgeeks.org/wp-content/uploads/the-end-unsmoothed-1024x819.png" alt="" width="665" height="532" /></p>
<p>Whoops! I think that looks more natural smoothed:</p>
<p><img loading="lazy" class="alignnone size-large wp-image-318453" src="https://cdncontribute.geeksforgeeks.org/wp-content/uploads/the-end-smoothed-1024x819.png" alt="" width="665" height="532" /></p>
<p>Thanks for reading. I hope things go “smoothly” for you in the future.</p>
</div>
]]></html><thumbnail_url><![CDATA[https://i2.wp.com/cdncontribute.geeksforgeeks.org/wp-content/uploads/how-to-smooth-a-polygon-1-1024x819.png?fit=440%2C330&ssl=1]]></thumbnail_url><thumbnail_width><![CDATA[413]]></thumbnail_width><thumbnail_height><![CDATA[330]]></thumbnail_height></oembed>