<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://algorist.com/algowiki_v2/index.php?action=history&amp;feed=atom&amp;title=TADM2E_4.27</id>
		<title>TADM2E 4.27 - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://algorist.com/algowiki_v2/index.php?action=history&amp;feed=atom&amp;title=TADM2E_4.27"/>
		<link rel="alternate" type="text/html" href="https://algorist.com/algowiki_v2/index.php?title=TADM2E_4.27&amp;action=history"/>
		<updated>2026-05-02T12:05:05Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.28.0</generator>

	<entry>
		<id>https://algorist.com/algowiki_v2/index.php?title=TADM2E_4.27&amp;diff=759&amp;oldid=prev</id>
		<title>Sonam: /* Solution */</title>
		<link rel="alternate" type="text/html" href="https://algorist.com/algowiki_v2/index.php?title=TADM2E_4.27&amp;diff=759&amp;oldid=prev"/>
				<updated>2020-06-29T10:27:37Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Solution&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 10:27, 29 June 2020&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l5&quot; &gt;Line 5:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 5:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Solution ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Solution ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Since a bullet through a vertex doesn't count as 2 walls, let's describe the polygon ''P'' in terms of pairs of points like [&amp;lt;math&amp;gt;(&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;x_0&lt;/del&gt;, y_1), (x_2, y_2)&amp;lt;/math&amp;gt;). That is, the first point will count as a wall, but the second will not.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Since a bullet through a vertex doesn't count as 2 walls, let's describe the polygon ''P'' in terms of pairs of points like [&amp;lt;math&amp;gt;(&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;x_1&lt;/ins&gt;, y_1), (x_2, y_2)&amp;lt;/math&amp;gt;). That is, the first point will count as a wall, but the second will not.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Next, let's convert all of the points in ''P'' to polar notation. We don't actually need to store the radius, however, just the angle &amp;lt;math&amp;gt;\theta&amp;lt;/math&amp;gt;. Also, the polar notation is relative to ''q'''s location, &amp;lt;math&amp;gt;(q_x, q_y)&amp;lt;/math&amp;gt;, so for every point ''p'' in ''P'' we have &amp;lt;math&amp;gt;\theta_p = atan((p_y - q_y) / (p_x - q_x))&amp;lt;/math&amp;gt;. These calculations are done on every point, so a computational complexity of &amp;lt;math&amp;gt;\Theta(n)&amp;lt;/math&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Next, let's convert all of the points in ''P'' to polar notation. We don't actually need to store the radius, however, just the angle &amp;lt;math&amp;gt;\theta&amp;lt;/math&amp;gt;. Also, the polar notation is relative to ''q'''s location, &amp;lt;math&amp;gt;(q_x, q_y)&amp;lt;/math&amp;gt;, so for every point ''p'' in ''P'' we have &amp;lt;math&amp;gt;\theta_p = atan((p_y - q_y) / (p_x - q_x))&amp;lt;/math&amp;gt;. These calculations are done on every point, so a computational complexity of &amp;lt;math&amp;gt;\Theta(n)&amp;lt;/math&amp;gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Sonam</name></author>	</entry>

	<entry>
		<id>https://algorist.com/algowiki_v2/index.php?title=TADM2E_4.27&amp;diff=500&amp;oldid=prev</id>
		<title>Volta: Probable solution, but would tickled if someone else could confirm or suggest another answer.</title>
		<link rel="alternate" type="text/html" href="https://algorist.com/algowiki_v2/index.php?title=TADM2E_4.27&amp;diff=500&amp;oldid=prev"/>
				<updated>2017-02-05T21:20:28Z</updated>
		
		<summary type="html">&lt;p&gt;Probable solution, but would tickled if someone else could confirm or suggest another answer.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Problem ==&lt;br /&gt;
&lt;br /&gt;
4-27. Let ''P'' be a simple, but not necessarily convex, polygon, and ''q'' an arbitrary point not necessarily in ''P''. Design an efficient algorithm to find a line segment originating from ''q'' that intersects the maximum number of edges of ''P''. In other words, if standing at point ''q'', in what direction should you aim a gun so the bullet will go through the largest number of walls? A bullet through a vertex of ''P'' gets credit for only one wall. An ''O(n lg n)'' algorithm is possible.&lt;br /&gt;
&lt;br /&gt;
== Solution ==&lt;br /&gt;
&lt;br /&gt;
Since a bullet through a vertex doesn't count as 2 walls, let's describe the polygon ''P'' in terms of pairs of points like [&amp;lt;math&amp;gt;(x_0, y_1), (x_2, y_2)&amp;lt;/math&amp;gt;). That is, the first point will count as a wall, but the second will not.&lt;br /&gt;
&lt;br /&gt;
Next, let's convert all of the points in ''P'' to polar notation. We don't actually need to store the radius, however, just the angle &amp;lt;math&amp;gt;\theta&amp;lt;/math&amp;gt;. Also, the polar notation is relative to ''q'''s location, &amp;lt;math&amp;gt;(q_x, q_y)&amp;lt;/math&amp;gt;, so for every point ''p'' in ''P'' we have &amp;lt;math&amp;gt;\theta_p = atan((p_y - q_y) / (p_x - q_x))&amp;lt;/math&amp;gt;. These calculations are done on every point, so a computational complexity of &amp;lt;math&amp;gt;\Theta(n)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Keep a list of the line segments, with points stored as pairs of angles relative to ''q'', and sort them by the minimum of the two angles. It is okay to switch which angle comes first in a pair, but the pairs must move together when they are sorted. It is also important to preserve knowledge of which point was the ''source'' (closed interval) and which was the ''destination'' (open interval), so we don't count one vertex twice. This sorting costs ''O(n lg n)'', and it is the dominant factor in this algorithm.&lt;br /&gt;
&lt;br /&gt;
Finally, iterate through the sorted list of minimum elements, incrementing a counter whenever the start of a line segment is encountered, and decrementing the counter whenever a line segment ends.&lt;/div&gt;</summary>
		<author><name>Volta</name></author>	</entry>

	</feed>