• Advertisement
Sign in to follow this  

Intersection point between lines

This topic is 3812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'd like someone to have a look at two functions I created that calculate the intersection point between a line and a vertical line parallel to the y axis or a horizontal line parallel to the x axis respectively. The functions seemed to work but now I'm getting unexpected behaviour in my program and I believe one of these functions is the culprit. Any comments would be welcome.
	float _xIntersect(float y, const Line2f& line2) const
	{
		float A2 = line2.y2-line2.y1, 
			  B2 = line2.x1-line2.x2, 
			  C2 = A2*line2.x1 + B2*line2.y1;

		_ASSERT(A2 != 0);

		return(-(B2*y - C2)/A2);
	}


	float _yIntersect(float x, const Line2f& line2) const
	{
//		A1=1, B1=0, C1=x, det = B1
		float A2 = line2.y2-line2.y1, 
			  B2 = line2.x1-line2.x2, 
			  C2 = A2*line2.x1 + B2*line2.y1;

		_ASSERT(-B2 != 0);

		return((C2-A2*x)/B2);
	}
[Edited by - hellraiser on September 14, 2007 11:18:41 PM]

Share this post


Link to post
Share on other sites
Advertisement
Just to say I've found out what the problem was and it is not related to any of these functions. They're working just fine!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement