k*j 发帖数: 153 | 1 careercup那本书上一道题。
10.3 Given two lines on a Cartesian plane, determine whether the two lines
would intersect.
书里是用slope来做。
return abs(line1.slope-line2.slope)>esp || abs(line1.yintercept - line2.
yintercept) < esp
但明显这没有考虑slope infinite的情况。所以不是很好的solution.
想问问这题有没有更general的解法呢?多谢! |
s*****y 发帖数: 897 | 2 use expression
y = ax + b to represent a line then. |
i***e 发帖数: 452 | |
l*******r 发帖数: 511 | 4 更general的考虑radon transform跟hough transform吧
【在 k*j 的大作中提到】 : careercup那本书上一道题。 : 10.3 Given two lines on a Cartesian plane, determine whether the two lines : would intersect. : 书里是用slope来做。 : return abs(line1.slope-line2.slope)>esp || abs(line1.yintercept - line2. : yintercept) < esp : 但明显这没有考虑slope infinite的情况。所以不是很好的solution. : 想问问这题有没有更general的解法呢?多谢!
|
k****n 发帖数: 369 | 5 in Cartesian plane, this is so far the best solution.
You may add specal case branching, but no major difference.
【在 k*j 的大作中提到】 : careercup那本书上一道题。 : 10.3 Given two lines on a Cartesian plane, determine whether the two lines : would intersect. : 书里是用slope来做。 : return abs(line1.slope-line2.slope)>esp || abs(line1.yintercept - line2. : yintercept) < esp : 但明显这没有考虑slope infinite的情况。所以不是很好的solution. : 想问问这题有没有更general的解法呢?多谢!
|
l***i 发帖数: 1309 | 6 A1*x + B1*y + C1=0
A2*x + B2*y + C2=0
Solve a linear system.
need to check when det(A1,A2,B1,B2)=0 |
s*******1 发帖数: 3820 | |