Santosh And His LightSabers
All submissions for this problem are available.
Being the android programmer geek, Santosh is; he wanted to create a game for the newly releasing Starwars franchise. But currently he's stuck. When two light sabers strike he doesn't know where they struck each other to animate the hit. Note that the light sabers would never be co-linear since that would destroy it's core.
Given two line segments representing the light saber, find if the given line segments intersect with each other. If they intersect, print their intersection point, else print -1.
The first line of Input contains an integer T denoting the T test cases.
In each line of the next T lines, we have 8 space seperated integers. x1, y1, x2, y2, x3, y3, x4, y4, The first two and the next two represent the x,y co-ordinates of the first line. Similarly the 3rd and 4th pair of points represent the second line.
Print T lines. In each line print the intersection point xi,yi. If No intersection exists, print -1 instead.
Should contain all the constraints on the input data that you may have. Format it like:
- 1 ≤ T ≤ 100
- -100 ≤ Xi ≤ 100
- -100 ≤ Yi ≤ 100
Input: 2 0 0 10 0 5 5 5 -5 0 0 0 10 8 0 8 -9 Output: 5.0 0.0 -1
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.