Poj 1410 intersection between rectangle and Line Segments

Source: Internet
Author: User

[Cpp]
# Include <iostream>
# Include <cstring>
# Include <cmath>
# Include <algorithm>
Using namespace std;
Struct point
{
Int x, y;
};
Int xj (point x1, point x2, point x3, point x4) // intersection is 1, not 0
{
If (min (x1.x, x2.x)> max (x3.x, x4.x) | min (x1.y, x2.y)> max (x3.y, x4.y)
| Min (x3.x, x4.x)> max (x1.x, x2.x) | min (x3.y, x4.y)> max (x1.y, x2.y)
)
Return 0; // do not submit: the rectangle is excluded from the experiment. The smallest value is greater than the maximum value.
Int a, B, c, d;
A = (x1.x-x2.x) * (x3.y-x1.y)-(x1.y-x2.y) * (x3.x-x1.x); // Cross-Site Experiment
B = (x1.x-x2.x) * (x4.y-x1.y)-(x1.y-x2.y) * (x4.x-x1.x );
C = (x3.x-x4.x) * (x1.y-x3.y)-(x3.y-x4.y) * (x1.x-x3.x );
D = (x3.x-x4.x) * (x2.y-x3.y)-(x3.y-x4.y) * (x2.x-x3.x );
Return a * B <= 0 & c * d <= 0;
}
Int main (void)
{
Int t;
Point x1, x2, j1, j2, j3, j4;
Cin> t;
While (t --)
{
Cin> x1.x> x1.y> x2.x> x2.y> j1.x> j1.y> j3.x> j3.y;
J2.x = j1.x; j2.y = j3.y;
J4.x = j3.x; j4.y = j1.y;
If (min (x1.x, x2.x)> min (j1.x, j3.x) & max (x1.x, x2.x) <max (j1.x, j3.x )&&
Min (x1.y, x2.y)> min (j1.y, j3.y) & max (x1.y, x2.y) <max (j1.y, j3.y ))
{Cout <"T" <endl; continue ;}// determines whether the data is in the internal directory.
If (xj (x1, x2, j1, j2) | xj (x1, x2, j2, j3) | xj (x1, x2, j3, j4) | xj (x1, x2, j4, j1 ))
Cout <"T" <endl; // if one side is intersecting
Else cout <"F" <endl;
}
Author: liang5630

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.