I have one line (two point (x,y) (x1,y1)) and a rectangle with focus point (rx,ry). I need help to find out collision point between line and rectangle, an example in C++ will be help.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t see how you can represent a rectangle with just a “focus point”. You’ll need either the two corner points or one corner point with a width/height/rotation set of data.
However, once you have a rectangle, I would simply break it down into four lines and do the intercept checks between each of those four lines and the line you want to check against.
Doing a search on SO for “line intersection” turns up numerous questions, including this one, which seems promising. In fact, searching for “line rectangle intersection” gives you this one, which seems to be exactly what you’re after.