Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

lone_ranger

Line in a rect

This topic is 5616 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

Advertisement
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

  • 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!