Line in a rect
Is the line infinite ( a ray ) or is this a line from point a to point b?
ToohrVyk
-------------
Extatica - a free 3d game engine
Available soon!
Click here to learn more
ToohrVyk
-------------
Extatica - a free 3d game engine
Available soon!
Click here to learn more
in 2d?
bool PointInRect(POINT point, RECT Rect)
{
if(point.x < Rect.Rightt&&point.x > Rect.Left)
{
if(point.y < Rect.Top&&point.y > Rect.Bottom)
return true;
}
return false;
}
[edited by - RhoneRanger on March 3, 2003 5:49:55 PM]
[edited by - RhoneRanger on March 3, 2003 5:50:49 PM]
bool PointInRect(POINT point, RECT Rect)
{
if(point.x < Rect.Rightt&&point.x > Rect.Left)
{
if(point.y < Rect.Top&&point.y > Rect.Bottom)
return true;
}
return false;
}
[edited by - RhoneRanger on March 3, 2003 5:49:55 PM]
[edited by - RhoneRanger on March 3, 2003 5:50:49 PM]
If either point of the line segment is inside the rectangle, the line is inside.
If that check fails, then if the line segment intersects any of the rectangle sides, the line is inside.
[edited by - Waverider on March 3, 2003 6:27:20 PM]
If that check fails, then if the line segment intersects any of the rectangle sides, the line is inside.
[edited by - Waverider on March 3, 2003 6:27:20 PM]
JEESH
You can use the same function though.
a line is simply 2 connected points right???
bool LineInRect(POINT LineStart,POINT LineEnd,RECT Rect)
{
if(PointInRect(LineStart,Rect)
{
if(PointInRect(LineEnd,Rect)
return true;
}
return false;
}
[edited by - RhoneRanger on March 3, 2003 6:30:21 PM]
You can use the same function though.
a line is simply 2 connected points right???
bool LineInRect(POINT LineStart,POINT LineEnd,RECT Rect)
{
if(PointInRect(LineStart,Rect)
{
if(PointInRect(LineEnd,Rect)
return true;
}
return false;
}
[edited by - RhoneRanger on March 3, 2003 6:30:21 PM]
It is possible for both points to be outside the rectangle but still have the line be inside, though. Your function works well for the point check. Another function will have to be written for the intersection with the rectangle sides.
Are we talking about total containment or just crossing the edges?
[edited by - Waverider on March 3, 2003 6:36:29 PM]
Are we talking about total containment or just crossing the edges?
[edited by - Waverider on March 3, 2003 6:36:29 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement