<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Determining if an angle causes polygon to be concave.</title>
		<link>http://www.allegro.cc/forums/view/585899</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 14 Jun 2006 07:45:58 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>http://solarimpact.servegame.com/poly1.jpg</p><p>Ok, for example, I have polygon ABCDEFG. During triangulation, I need to test if the angle in the &quot;test triangle&quot; has a segment that lies outside of the polygon.</p><p>In this picture, my current triangulation algorithm first will try ABC. It is correct, so point B is now ignored from further triangulation. Now, it moves on to ACD, which is incorrect (as AD lies outside of the polygon). This is due to the fact that angle C is &gt; 180°. I need to find a quick, easy way to check for this in order to correct the problem that arises.</p><p>In IRC, I was discussing a few different methods with several people, but could not decide on a single efficient method. So, I come to you people: the Allegro group! What is the quickest, easiest way of checking if this angle will cause a concave in the rest of the angle? I was thinking of finding the angle at C, and check if it&#39;s greater than 180° or not...but, how would you do this? Would the math slow it down too much?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elverion)</author>
		<pubDate>Wed, 14 Jun 2006 01:07:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I haven&#39;t fully thought this through, so take this with great care: I just had the idea that it should be also possible to check if AD intersects with the polygon (points A and D excluded, of course). If it does, it&#39;s concave, if it doesn&#39;t, everything&#39;s fine.</p><p>I doubt that this&#39;d be any faster, though.</p><p>The angle approach seems fine. I&#39;d probably use the scalar product for that.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Indeterminatus)</author>
		<pubDate>Wed, 14 Jun 2006 01:48:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was thinking...if I can find the two angles using atan2, then subtract that from 360, it should give the angle at B, right? Or maybe my logic here is flawed.</p><p>The math I&#39;m using is:
</p><div class="source-code snippet"><div class="inner"><pre>  <span class="k1">float</span> angle1 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/fixtof" target="_blank"><span class="a">fixtof</span></a><span class="k2">(</span> <a href="http://www.allegro.cc/manual/fixatan2" target="_blank"><span class="a">fixatan2</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/itofix" target="_blank"><span class="a">itofix</span></a><span class="k2">(</span>poly<span class="k2">[</span>c<span class="k2">]</span>.y <span class="k3">-</span> poly<span class="k3">&lt;</span>b&gt;.y<span class="k2">)</span>, <a href="http://www.allegro.cc/manual/itofix" target="_blank"><span class="a">itofix</span></a><span class="k2">(</span>poly<span class="k2">[</span>c<span class="k2">]</span>.x <span class="k3">-</span> poly<span class="k3">&lt;</span>b&gt;.x<span class="k2">)</span><span class="k2">)</span> <span class="k2">)</span><span class="k2">;</span>
  <span class="k1">float</span> angle2 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/fixtof" target="_blank"><span class="a">fixtof</span></a><span class="k2">(</span> <a href="http://www.allegro.cc/manual/fixatan2" target="_blank"><span class="a">fixatan2</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/itofix" target="_blank"><span class="a">itofix</span></a><span class="k2">(</span>poly<span class="k2">[</span>a<span class="k2">]</span>.y <span class="k3">-</span> poly<span class="k3">&lt;</span>b&gt;.y<span class="k2">)</span>, <a href="http://www.allegro.cc/manual/itofix" target="_blank"><span class="a">itofix</span></a><span class="k2">(</span>poly<span class="k2">[</span>a<span class="k2">]</span>.x <span class="k3">-</span> poly<span class="k3">&lt;</span>b&gt;.x<span class="k2">)</span><span class="k2">)</span> <span class="k2">)</span><span class="k2">;</span>
  <span class="k1">float</span> angleb <span class="k3">=</span> <span class="n">360</span> <span class="k3">-</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_38.html" target="_blank">abs</a><span class="k2">(</span>angle1<span class="k2">)</span> <span class="k3">-</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_38.html" target="_blank">abs</a><span class="k2">(</span>angle2<span class="k2">)</span><span class="k2">;</span>
  
  <a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><span class="s">"Angle1 is: %f\nAngle2 is: %f\nAngle B must be: %f"</span>, angle1, angle2, angleb<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

angle1 and angle2 are occasionally negative...is that correct? To compensate for that, I just used their absolute values in finding angleb. My problem here now is that angleb is almost always &gt; 200.0, which can&#39;t be correct. What am I doing wrong?</p><p>So then I was thinking, instead of subtracting from 360, and checking if it&#39;s &gt; 180, to subtract from 180, and check if it&#39;s greater than 90. The numbers looked right...but the graph didn&#39;t.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elverion)</author>
		<pubDate>Wed, 14 Jun 2006 02:55:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hmm.. why use this:<br /><span class="source-code"><span class="k1">float</span> angle1 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/fixtof" target="_blank"><span class="a">fixtof</span></a><span class="k2">(</span> <a href="http://www.allegro.cc/manual/fixatan2" target="_blank"><span class="a">fixatan2</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/itofix" target="_blank"><span class="a">itofix</span></a><span class="k2">(</span>poly<span class="k2">[</span>c<span class="k2">]</span>.y <span class="k3">-</span> poly<span class="k3">&lt;</span>b&gt;.y<span class="k2">)</span>, <a href="http://www.allegro.cc/manual/itofix" target="_blank"><span class="a">itofix</span></a><span class="k2">(</span>poly<span class="k2">[</span>c<span class="k2">]</span>.x <span class="k3">-</span> poly<span class="k3">&lt;</span>b&gt;.x<span class="k2">)</span><span class="k2">)</span> <span class="k2">)</span><span class="k2">;</span></span><br />instead of this ?<br /><span class="source-code"><span class="k1">float</span> angle1 <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_50.html" target="_blank">atan2</a><span class="k2">(</span><span class="k2">(</span>poly<span class="k2">[</span>c<span class="k2">]</span>.y <span class="k3">-</span> poly<span class="k3">&lt;</span>b&gt;.y<span class="k2">)</span>, <span class="k2">(</span>poly<span class="k2">[</span>c<span class="k2">]</span>.x <span class="k3">-</span> poly<span class="k3">&lt;</span>b&gt;.x<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (hazul)</author>
		<pubDate>Wed, 14 Jun 2006 03:02:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Hmm.. why use this:<br />...<br />instead of this ?
</p></div></div><p>
163 C:\poly_test\c_poly.cpp conversion from `int&#39; to non-scalar type `fix&#39; requested </p><p>Already tried it.</p><p>It has occured to me that fixatan2 uses &quot;Allegro degrees&quot;, right? I&#39;ve modified my code to:
</p><div class="source-code snippet"><div class="inner"><pre>  <span class="k1">float</span> angle1 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/fixtof" target="_blank"><span class="a">fixtof</span></a><span class="k2">(</span> <a href="http://www.allegro.cc/manual/fixatan2" target="_blank"><span class="a">fixatan2</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/itofix" target="_blank"><span class="a">itofix</span></a><span class="k2">(</span>poly<span class="k2">[</span>c<span class="k2">]</span>.y <span class="k3">-</span> poly<span class="k3">&lt;</span>b&gt;.y<span class="k2">)</span>, <a href="http://www.allegro.cc/manual/itofix" target="_blank"><span class="a">itofix</span></a><span class="k2">(</span>poly<span class="k2">[</span>c<span class="k2">]</span>.x <span class="k3">-</span> poly<span class="k3">&lt;</span>b&gt;.x<span class="k2">)</span><span class="k2">)</span> <span class="k2">)</span><span class="k2">;</span>
  <span class="k1">float</span> angle2 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/fixtof" target="_blank"><span class="a">fixtof</span></a><span class="k2">(</span> <a href="http://www.allegro.cc/manual/fixatan2" target="_blank"><span class="a">fixatan2</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/itofix" target="_blank"><span class="a">itofix</span></a><span class="k2">(</span>poly<span class="k2">[</span>a<span class="k2">]</span>.y <span class="k3">-</span> poly<span class="k3">&lt;</span>b&gt;.y<span class="k2">)</span>, <a href="http://www.allegro.cc/manual/itofix" target="_blank"><span class="a">itofix</span></a><span class="k2">(</span>poly<span class="k2">[</span>a<span class="k2">]</span>.x <span class="k3">-</span> poly<span class="k3">&lt;</span>b&gt;.x<span class="k2">)</span><span class="k2">)</span> <span class="k2">)</span><span class="k2">;</span>
  <span class="k1">float</span> angleb <span class="k3">=</span> <span class="n">256</span> <span class="k3">-</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_38.html" target="_blank">abs</a><span class="k2">(</span> <span class="k2">(</span><span class="k2">(</span><span class="n">128</span><span class="k3">-</span>angle1<span class="k2">)</span> <span class="k3">-</span> <span class="k2">(</span><span class="n">256</span><span class="k3">-</span>angle2<span class="k2">)</span><span class="k2">)</span> <span class="k2">)</span><span class="k2">;</span>
  
  <span class="k1">if</span> <span class="k2">(</span> <span class="k2">(</span>angleb <span class="k3">&lt;</span> <span class="n">0</span><span class="k2">)</span> <span class="k3">|</span><span class="k3">|</span> <span class="k2">(</span>angleb <span class="k3">&gt;</span> <span class="n">192</span><span class="k2">)</span> <span class="k2">)</span>
    <span class="k1">return</span> <span class="k1">false</span><span class="k2">;</span>
</pre></div></div><p>

Everything seems to be in order now, so long as points are NOT entered in a clockwise fashion. I&#39;ll have to keep testing polygon after polygon to make sure that everything is in order.</p><p>Even though you may not have given me the perfect answer, I always look forward to your feedback, and your replies made me think down the right path. So, cookies to you both.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elverion)</author>
		<pubDate>Wed, 14 Jun 2006 03:21:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
C:\poly_test\c_poly.cpp conversion from `int&#39; to non-scalar type `fix&#39; requested
</p></div></div><p>
Allegro&#39;s damned fix C++ class. The most evil thing to &quot;grace&quot; Allegro that I know of. You can either define this on the command line, or before anywhere you include Allegro:<br /><tt>ALLEGRO_NO_FIX_CLASS</tt>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Wed, 14 Jun 2006 07:45:58 +0000</pubDate>
	</item>
</rss>
