Jump to content
  • Advertisement
Sign in to follow this  
hellraiser

Intersection point between lines

This topic is 3991 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!