Question
Write a Java program that reads a line and a line segment and then determines whether they intersect or not. When they overlap completely, consider
Write a Java program that reads a line and a line segment and then determines whether they intersect or not. When they overlap completely, consider that as intersecting. Use variables ((lp1x, lp1y), (lp2x, lp2y)) to represent a line and ((sp1x, sp1y), (sp2x, sp2y)) to represent a line segment. Some examples:
((lp1x, lp1y), (lp2x, lp2y)) ((sp1x, sp1y), (sp2x, sp2y)) outputs
((0, 0), (5, 4)) ((4, 0), (0, 4)) intersecting
((0, 0), (5, 5)) ((1, 1), (4, 4)) intersecting
((2, 1), (6, 1)) ((4, 1), (5, 4)) intersecting
((0, 0), (5, 4)) ((2, 0), (4, 1)) non-intersecting
((1, 1), (1, 4)) ((2, 3), (5, 3)) non-intersecting
Divide the problem into four cases using a nested if statement after checking on the inputs:
vertical line and vertical line segment
vertical line and non-vertical line segment
non-vertical line and vertical line segment
non-vertical line and non-vertical line segment
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started