<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Line-Line Intersection in C++</title>
	<atom:link href="http://flassari.is/2008/11/line-line-intersection-in-cplusplus/feed/" rel="self" type="application/rss+xml" />
	<link>http://flassari.is/2008/11/line-line-intersection-in-cplusplus/</link>
	<description></description>
	<lastBuildDate>Wed, 09 May 2012 13:29:17 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
	<item>
		<title>By: David Sopala</title>
		<link>http://flassari.is/2008/11/line-line-intersection-in-cplusplus/#comment-1345</link>
		<dc:creator>David Sopala</dc:creator>
		<pubDate>Thu, 22 Mar 2012 01:57:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.flassari.is/?p=41#comment-1345</guid>
		<description>Don&#039;t return a bool to check multiple line intersections, you MUST return a point.  When you have a point from the first two lines check to see if the point is valid for the 3,4,5...n lines if all return true then yes they all intersect.</description>
		<content:encoded><![CDATA[<p>Don&#8217;t return a bool to check multiple line intersections, you MUST return a point.  When you have a point from the first two lines check to see if the point is valid for the 3,4,5&#8230;n lines if all return true then yes they all intersect.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Washechek</title>
		<link>http://flassari.is/2008/11/line-line-intersection-in-cplusplus/#comment-139</link>
		<dc:creator>Brian Washechek</dc:creator>
		<pubDate>Thu, 12 May 2011 02:55:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.flassari.is/?p=41#comment-139</guid>
		<description>I don&#039;t get it. Are you making fun of how little I know?</description>
		<content:encoded><![CDATA[<p>I don&#8217;t get it. Are you making fun of how little I know?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: varsha</title>
		<link>http://flassari.is/2008/11/line-line-intersection-in-cplusplus/#comment-30</link>
		<dc:creator>varsha</dc:creator>
		<pubDate>Wed, 23 Mar 2011 05:22:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.flassari.is/?p=41#comment-30</guid>
		<description>@Brian Washechek 
I ahve problen in C
I am trying to find intersection of multilines but failed it only gives 1st two 

how should i check for multiple line intersection if I return boolean status i can check but how to reshuffle the end point each time</description>
		<content:encoded><![CDATA[<p>@Brian Washechek<br />
I ahve problen in C<br />
I am trying to find intersection of multilines but failed it only gives 1st two </p>
<p>how should i check for multiple line intersection if I return boolean status i can check but how to reshuffle the end point each time</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen</title>
		<link>http://flassari.is/2008/11/line-line-intersection-in-cplusplus/#comment-29</link>
		<dc:creator>Stephen</dc:creator>
		<pubDate>Tue, 08 Mar 2011 14:17:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.flassari.is/?p=41#comment-29</guid>
		<description>Lets try that again taking account of HTML :)


if (x &lt; (min(x1, x2) - epsilon) &#124;&#124;
    x &gt; (max(x1, x2) + epsilon) &#124;&#124;
    x &lt; (min(x3, x4) - epsilon) &#124;&#124;
    x &gt; (max(x3, x4) + epsilon))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return false;
if (y &lt; (min(y1, y2) - epsilon) &#124;&#124;
    y &gt; (max(y1, y2) + epsilon) &#124;&#124;
    y &lt; (min(y3, y4) - epsilon) &#124;&#124;
    y &gt; (max(y3, y4) + epsilon))
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return false;</description>
		<content:encoded><![CDATA[<p>Lets try that again taking account of HTML :)</p>
<p>if (x &lt; (min(x1, x2) - epsilon) ||<br />
    x &gt; (max(x1, x2) + epsilon) ||<br />
    x &lt; (min(x3, x4) - epsilon) ||<br />
    x &gt; (max(x3, x4) + epsilon))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br />
if (y &lt; (min(y1, y2) - epsilon) ||<br />
    y &gt; (max(y1, y2) + epsilon) ||<br />
    y &lt; (min(y3, y4) - epsilon) ||<br />
    y &gt; (max(y3, y4) + epsilon))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen</title>
		<link>http://flassari.is/2008/11/line-line-intersection-in-cplusplus/#comment-28</link>
		<dc:creator>Stephen</dc:creator>
		<pubDate>Tue, 08 Mar 2011 14:01:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.flassari.is/?p=41#comment-28</guid>
		<description>Your test for x &amp; y being within the lines extent will often fail when one or other of the lines is either horizontal or vertical due to floating point rounding errors.

A better test would be:
        if (x  (std::max(x1, x2) + epsilon) &#124;&#124;
            x  (std::max(x3, x4) + epsilon))
            return false;
        if (y  (std::max(y1, y2) + epsilon) &#124;&#124;
            y  (std::max(y3, y4) + epsilon))
            return false;

Where epsilon is say, 1e-5.  This has the effect of testing against a line with a thickness of 2*epsilon accommodating any rounding errors.</description>
		<content:encoded><![CDATA[<p>Your test for x &amp; y being within the lines extent will often fail when one or other of the lines is either horizontal or vertical due to floating point rounding errors.</p>
<p>A better test would be:<br />
        if (x  (std::max(x1, x2) + epsilon) ||<br />
            x  (std::max(x3, x4) + epsilon))<br />
            return false;<br />
        if (y  (std::max(y1, y2) + epsilon) ||<br />
            y  (std::max(y3, y4) + epsilon))<br />
            return false;</p>
<p>Where epsilon is say, 1e-5.  This has the effect of testing against a line with a thickness of 2*epsilon accommodating any rounding errors.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Washechek</title>
		<link>http://flassari.is/2008/11/line-line-intersection-in-cplusplus/#comment-27</link>
		<dc:creator>Brian Washechek</dc:creator>
		<pubDate>Sun, 28 Nov 2010 23:55:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.flassari.is/?p=41#comment-27</guid>
		<description>Here is mycode
bool intersection(float x1,float y1,
                  float x2,float y2,
                  float x3,float y3,
                  float x4,float y4) { 
// Store the values for fast access and easy 
    
// equations-to-code conversion 
    
//float x1 = p1.x, x2 = p2.x, x3 = p3.x, x4 = p4.x;    
//float y1 = p1.y, y2 = p2.y, y3 = p3.y, y4 = p4.y; 
 
    
float d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); 
// If d is zero, there is no intersection 
    
if (d == 0) return false; 
    
// Get the x and y 
    
float pre = (x1*y2 - y1*x2), post = (x3*y4 - y3*x4); 
    
float x = ( pre * (x3 - x4) - (x1 - x2) * post ) / d;   
float y = ( pre * (y3 - y4) - (y1 - y2) * post ) / d; 
 
// Check if the x and y coordinates are within both lines 
    
if ( x  max(x1, x2) &#124;&#124; 
x  max(x3, x4) ) return false; 
if ( y  max(y1, y2) &#124;&#124;         
y  max(y3, y4) ) return false; 
 

// Return the point of intersection 
//But I don&#039;t care about &quot;where&quot;, only &quot;if&quot;
//Point* ret = new Point(); 
//ret-&gt;x = x; 
//ret-&gt;y = y; 
    
return true; 
}


void fixCollisions()
{
  bigX=true;          //Here&#039;s the problem. Not with the hit detection math, but with the display
                      //of results
   for (int i =0;i&lt;wallUbound;i++)                         
      {

           if (intersection(FDX-cos(FDA),FDY-sin(FDA),   //&lt;--Right here
                           FDX+cos(FDA)+10,FDY+sin(FDA),                         
                           wallX[i]-cos(wallRot[i]),wallY[i]-sin(wallRot[i]),
                           wallX[i]+cos(wallRot[i]),wallY[i]+sin(wallRot[i])))
                           bigX=true;

      }      

}</description>
		<content:encoded><![CDATA[<p>Here is mycode<br />
bool intersection(float x1,float y1,<br />
                  float x2,float y2,<br />
                  float x3,float y3,<br />
                  float x4,float y4) {<br />
// Store the values for fast access and easy </p>
<p>// equations-to-code conversion </p>
<p>//float x1 = p1.x, x2 = p2.x, x3 = p3.x, x4 = p4.x;<br />
//float y1 = p1.y, y2 = p2.y, y3 = p3.y, y4 = p4.y; </p>
<p>float d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);<br />
// If d is zero, there is no intersection </p>
<p>if (d == 0) return false; </p>
<p>// Get the x and y </p>
<p>float pre = (x1*y2 - y1*x2), post = (x3*y4 - y3*x4); </p>
<p>float x = ( pre * (x3 - x4) - (x1 - x2) * post ) / d;<br />
float y = ( pre * (y3 - y4) - (y1 - y2) * post ) / d; </p>
<p>// Check if the x and y coordinates are within both lines </p>
<p>if ( x  max(x1, x2) ||<br />
x  max(x3, x4) ) return false;<br />
if ( y  max(y1, y2) ||<br />
y  max(y3, y4) ) return false; </p>
<p>// Return the point of intersection<br />
//But I don&#8217;t care about &#8220;where&#8221;, only &#8220;if&#8221;<br />
//Point* ret = new Point();<br />
//ret-&gt;x = x;<br />
//ret-&gt;y = y; </p>
<p>return true;<br />
}</p>
<p>void fixCollisions()<br />
{<br />
  bigX=true;          //Here&#8217;s the problem. Not with the hit detection math, but with the display<br />
                      //of results<br />
   for (int i =0;i&lt;wallUbound;i++)<br />
      {</p>
<p>           if (intersection(FDX-cos(FDA),FDY-sin(FDA),   //&lt;--Right here<br />
                           FDX+cos(FDA)+10,FDY+sin(FDA),<br />
                           wallX[i]-cos(wallRot[i]),wallY[i]-sin(wallRot[i]),<br />
                           wallX[i]+cos(wallRot[i]),wallY[i]+sin(wallRot[i])))<br />
                           bigX=true;</p>
<p>      }      </p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BNelsey</title>
		<link>http://flassari.is/2008/11/line-line-intersection-in-cplusplus/#comment-26</link>
		<dc:creator>BNelsey</dc:creator>
		<pubDate>Wed, 03 Nov 2010 11:40:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.flassari.is/?p=41#comment-26</guid>
		<description>still learning C++ and this definitely helped me, thanks a bunch!</description>
		<content:encoded><![CDATA[<p>still learning C++ and this definitely helped me, thanks a bunch!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phloxi</title>
		<link>http://flassari.is/2008/11/line-line-intersection-in-cplusplus/#comment-25</link>
		<dc:creator>Phloxi</dc:creator>
		<pubDate>Tue, 25 May 2010 14:33:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.flassari.is/?p=41#comment-25</guid>
		<description>You bloody beauty.</description>
		<content:encoded><![CDATA[<p>You bloody beauty.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

