posted 1 year ago
I need to implement the method intersection(Line) in class Line. It must return a Point of intersection of two lines.
Note that lines are defined by linear equations: y = k * x + b. Line constructor takes k and b coefficients as parameters.
If lines coincide or do not intersect, the method must return null. It may seem surprising that we use int for arguments and fields of coordinates. The point is that using double will bring some extra complexity we want to avoid for this basic exercise. All tests are selected in to induce calculations without remainders.
You may check your result in class Main.
This is the class where I implement the solution:
This is the Point class:
And last class, which is Main class:
This are my tests:
"1,2,2,1, result (1;3)",
"1,0,2,0, result (0;0)",
"4,3,1,3, result (0;3)",
They are correct.
What I don't know how to do is for the time when the lines coincide or do not intersect, the method must return null.
"0,0,0,0", "1,1,1,1", "3,-9,3,-9"
How can I do that?