#5040·kornia

`fit_line` 为 2-D 点使用 y-on-x 普通最小二乘法拟合,但对于 D ≥ 3 使用总最小二乘法,因此,一个接近垂直的 2-D 拟合结果偏离 8.26° (通过 D = 3 路径偏离 1.42°),结果在 x 和 y 交换后会发生变化,并且绝对的 `Σdx² > 1e-8` 测试会使小的点集变成垂直的。

作者: ducha-aiki创建于 2026年9月27日更新于 2026年9月28日

`fit_line(points, weights=None)` (`kornia/geometry/line.py:241`) has two algorithms. For D ≥ 3, it takes the principal direction of the scatter matrix (an SVD), which is the total least squares line: it minimizes the perpendicular distances. Since #3219, D = 2 goes to `_fit_line_ols_2d` / `_fit_line_weighted_ols_2d` (`:186-238`), which fit the slope of y on x by ordinary least squares: they minimize vertical distances and return `(1, slope)/‖·‖`. The two give different lines for the same points, and the 2-D one has three consequences: