Ninja and Geometry Problem Statement

In this problem, Ninja is provided with two lines on a 2D plane. The first line 'AB' is determined by two points A and B. The second line 'PQ' is determined by two points P and Q. The task is to calculate the intersection point of these two lines with precision up to six decimal places. If the lines do not intersect, the output should be -1.000000 -1.000000.

Input:

The first line provides an integer ‘T’ representing the number of test cases. Each test case consists of one line containing eight space-separated integers: 
‘AX1’, ‘AY1’, ‘BX2’, ‘BY2’, ‘PX1’, ‘PY1’, ‘QX2’, ‘QY2’

Output:

For each test case, output the intersection point’s coordinates (X, Y) with a precision of six decimal places on a new line. If there is no intersection, return -1.000000 -1.000000.

Example:

Input:
2
0 3 3 0 0 0 5 5
1 1 2 2 3 3 4 4
Output:
1.500000 1.500000
-1.000000 -1.000000
Explanation:

For the first test case, the lines intersect at (1.500000, 1.500000). For the second test case, the lines do not intersect, hence the output is -1.000000 -1.000000.

Constraints:

  • 1 <= ‘T’ <= 102
  • 1 <= ‘AX1’, ‘AY1’, ‘BX2’, ‘BY2’, ‘PX1’, ‘PY1’, ‘QX2’, ‘QY2’ <= 105
  • The lines ‘AB’ and ‘PQ’ are distinct.

Note:

You do not need to format the output to six decimal places manually; it’s handled in the function implementation. The problem may involve precision handling due to floating-point arithmetic.

Be the first one to answer
Add answer anonymously...
Atlassian Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter