上QQ阅读APP看书,第一时间看更新
29. Line-line intersection
Write a program that determines where two lines intersect. Let the user left-click twice to define one line and right-click twice to define another. Be sure that the program can handle horizontal and vertical lines, and the case when the lines are parallel.
Hint: Use a parametric definition for the lines as in p = p0 + t × v where p0 is a point on the line, v is a vector pointing in the direction of the line, and t is a real number parameter. If that doesn't make sense to you, then read the solution. You may want to stop after the explanation and try to implement the code yourself before you read the entire solution.