<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Overlapping Circles</title>
		<link>http://www.allegro.cc/forums/view/614565</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 18 Aug 2014 09:22:38 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I am playing around with the primitives library and I am wondering if there is any way to draw circles of different colours without them overlapping each other..?</p><p>like this:<br /><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/4/9/49ea9cbe178bf04fb8c264b6e17d3bbc.png" alt="lens1.png" width="240" height="180" /><br />(Imagine the circles are different colors)<br />rather than this:<br /><span class="remote-thumbnail"><span class="json">{"name":"40030d1336416221-how-find-distance-between-two-overlapping-circles-eclipse.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/e\/9e279ea0685bef975d4800699990efea.jpg","w":419,"h":290,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/e\/9e279ea0685bef975d4800699990efea"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/9/e/9e279ea0685bef975d4800699990efea-240.jpg" alt="40030d1336416221-how-find-distance-between-two-overlapping-circles-eclipse.jpg" width="240" height="166" /></span><br />For example to have the circles cut at line &#39;C&#39; so they don&#39;t overlap... <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>Is there a simple efficient way to go about this or should I stick to the same colour to give the illusion of not overlapping?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Splizard)</author>
		<pubDate>Sun, 17 Aug 2014 07:22:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Maybe this could be done with the stencil buffer</p><p><a href="http://en.wikipedia.org/wiki/Stencil_buffer">http://en.wikipedia.org/wiki/Stencil_buffer</a></p><p>Or perhaps when drawing the second circle you can use clipping rect.</p><p>Yeah, clipping rect can do this.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (jmasterx)</author>
		<pubDate>Sun, 17 Aug 2014 08:21:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It would be nice if I could do it without explicitly calling OpenGL <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>Thanks, but the clipping rectangle doesn&#39;t seem to work at any angle...
</p><pre>al_set_clipping_rectangle(int x, int y, int width, int height)</pre><p>
So I guess I would then need to rotate the coordinates to achieve this at different angles?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Splizard)</author>
		<pubDate>Sun, 17 Aug 2014 11:21:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The way to do this could be to calculate the 2 arcs using al_calculate_line, and then close the line piece by using al_calculate_line, then finally use al_draw_prim to draw the resulting figure. </p><p><a href="https://www.allegro.cc/manual/5/al_calculate_arc">https://www.allegro.cc/manual/5/al_calculate_arc</a></p><p>You can also use Allegro&#39;s transformations to translate and rotate coordinates.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Sun, 17 Aug 2014 13:23:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>i would convert the 2 circles into 2 arrays of raster lines <br />(same as you would for drawing triangles).<br />each raster has: <br />x1,   -left side of circle<br />x2,   -right side of circle<br />y,    -y coord of raster line<br />midx  -intersection coord (to be calculated)</p><p>so you can draw an entire circle by stepping through the array.</p><p>for y= y1 to y2<br />  draw_line (x1, y, x2, y, color);</p><p>NOTE: if you have an optimized draw_hline function, <br />this will be faster than a generic draw_line (for software rendering).<br />For opengl it might not matter.</p><p>1.<br />sort the circles so circle1 is on the left and circle2 on the right</p><p>2.<br />loop thru the raster array for each circle and calculate the intersection x-coord.<br />To get the even split down the middle, just average the overlapping<br />x coordinates.</p><p>do a bounding box check on the y coordinate first.<br />for each raster line (y coord) from circle1 that intersects circle2<br />then do bounds checking to determine if they intersect for x coordinates too</p><p>if (intersects)<br />  midx= the average of circle1_x2 and circle2_x1</p><p>3. draw each circle by looping through the raster lines.</p><p>circle1:<br />for y= y1 to y2<br />  draw_line (circle1_x1, y, midx-1, y, color)</p><p>circle2:<br />for y= y1 to y2<br />  draw_line (midx, y, circle2_x2, y, color) </p><p>obviously, if both circles aren&#39;t on the same y coordinate u have to do <br />the relative y-coord math when comparing the raster lines.</p><p>This should work for circles of different sizes too, i think.</p><p>this algorithm probably only works as long as 1 circle is not completely inside<br />the other circle1. You&#39;ll have to do the math to prevent that case from happening.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Pho75_)</author>
		<pubDate>Sun, 17 Aug 2014 18:36:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/614565/1004298#target">Splizard</a> said:</div><div class="quote"><p>
Thanks, but the clipping rectangle doesn&#39;t seem to work at any angle...</p><p>al_set_clipping_rectangle(int x, int y, int width, int height)
</p></div></div><p>
It works for me in this simple example :
</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span>
<span class="number">  2</span>
<span class="number">  3</span>
<span class="number">  4</span><span class="p">#include "allegro5/allegro.h"</span>
<span class="number">  5</span><span class="p">#include "allegro5/allegro_primitives.h"</span>
<span class="number">  6</span><span class="p">#include "allegro5/allegro_image.h"</span>
<span class="number">  7</span>
<span class="number">  8</span><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc , <span class="k1">char</span><span class="k3">*</span><span class="k3">*</span> argv<span class="k2">)</span> <span class="k2">{</span>
<span class="number">  9</span>   
<span class="number"> 10</span>   
<span class="number"> 11</span>   <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span><span class="k1">return</span> <span class="n">1</span><span class="k2">;</span><span class="k2">}</span>
<span class="number"> 12</span>   <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_init_primitives_addon"><span class="a">al_init_primitives_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span><span class="k1">return</span> <span class="n">2</span><span class="k2">;</span><span class="k2">}</span>
<span class="number"> 13</span>   <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span><span class="k1">return</span> <span class="n">3</span><span class="k2">;</span><span class="k2">}</span>
<span class="number"> 14</span>   
<span class="number"> 15</span>   <a href="http://www.allegro.cc/manual/al_set_new_display_flags"><span class="a">al_set_new_display_flags</span></a><span class="k2">(</span>ALLEGRO_WINDOWED<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>   <a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a><span class="k3">*</span> display <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span><span class="n">300</span>,<span class="n">200</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>   
<span class="number"> 18</span>   <a href="http://www.allegro.cc/manual/al_clear_to_color"><span class="a">al_clear_to_color</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>   
<span class="number"> 20</span>   <a href="http://www.allegro.cc/manual/al_set_clipping_rectangle"><span class="a">al_set_clipping_rectangle</span></a><span class="k2">(</span><span class="n">0</span>,<span class="n">0</span>,<span class="n">150</span>,<span class="n">200</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>   <a href="http://www.allegro.cc/manual/al_draw_filled_circle"><span class="a">al_draw_filled_circle</span></a><span class="k2">(</span><span class="n">100</span>,<span class="n">100</span>,<span class="n">100</span>,<a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>,<span class="n">255</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>   <a href="http://www.allegro.cc/manual/al_set_clipping_rectangle"><span class="a">al_set_clipping_rectangle</span></a><span class="k2">(</span><span class="n">150</span>,<span class="n">0</span>,<span class="n">150</span>,<span class="n">200</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 23</span>   <a href="http://www.allegro.cc/manual/al_draw_filled_circle"><span class="a">al_draw_filled_circle</span></a><span class="k2">(</span><span class="n">200</span>,<span class="n">100</span>,<span class="n">100</span>,<a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>,<span class="n">0</span>,<span class="n">255</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span>   
<span class="number"> 25</span>   <a href="http://www.allegro.cc/manual/al_save_bitmap"><span class="a">al_save_bitmap</span></a><span class="k2">(</span><span class="s">"primclip.png"</span> , <a href="http://www.allegro.cc/manual/al_get_backbuffer"><span class="a">al_get_backbuffer</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 26</span>   
<span class="number"> 27</span>   <a href="http://www.allegro.cc/manual/al_flip_display"><span class="a">al_flip_display</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 28</span>   
<span class="number"> 29</span>   <a href="http://www.allegro.cc/manual/al_rest"><span class="a">al_rest</span></a><span class="k2">(</span><span class="n">3</span>.<span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 30</span>   
<span class="number"> 31</span>   <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 32</span><span class="k2">}</span>
</div></div><p>

<span class="remote-thumbnail"><span class="json">{"name":"608871","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/f\/1f0a8f0ef5d0ec4a6895038594a8e6af.png","w":300,"h":200,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/f\/1f0a8f0ef5d0ec4a6895038594a8e6af"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/1/f/1f0a8f0ef5d0ec4a6895038594a8e6af-240.jpg" alt="608871" width="240" height="160" /></span></p><p>Though to get rotated &#39;molecules&#39; you would need to use a subbitmap to draw your circles on horizontally and then use the transformation matrix to draw it rotated on screen. The clipping gets applied after the transformation as far as I know.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 17 Aug 2014 22:53:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><a href="https://www.allegro.cc/forums/thread/612466/981759#target">The Master</a> has a great post on this.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Gideon Weems)</author>
		<pubDate>Sun, 17 Aug 2014 23:19:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@Edgar Reynaldo<br />It would be nice if you could set an arbitrary clipping line at any angle <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /><br />The need is for this to work at any angle, if you moved one of the circles around it would always merge with the other circle no matter which way they intersect.<br />Creating subitmaps seems maybe inefficient? If your dealing with large amounts of circles or &quot;Molecules&quot;.</p><p>Out of the solutions above which would theoretically be the most speed efficient way?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Splizard)</author>
		<pubDate>Mon, 18 Aug 2014 04:39:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;d think drawing actual lit 3D intersecting spheres would be easiest in the long run.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Mon, 18 Aug 2014 09:22:38 +0000</pubDate>
	</item>
</rss>
