# Intersection point between lines

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

## 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 on other sites
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!

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633330
• Total Posts
3011388
• ### Who's Online (See full list)

There are no registered users currently online

×