Wrong line intersection point calculation
banderlog opened this issue · 6 comments
from skspatial.objects import Line, Point, Vector
from skspatial.plotting import plot_2d
import math
import numpy as np
def get_direction(compass_deg):
rad = math.pi * compass_deg / 180
y = math.cos(rad)
x = math.sin(rad)
print(f'{round(x, 3)},{round(y, 3)}')
return x, y
point_1=Point([0, 0])
point_2=Point([0, 1])
line_1 = Line(point_1, direction=get_direction(270))
line_2 = Line(point_2, direction=get_direction(92))
point_12 = Point(line_1.intersect_line(line_2))
_, ax = plot_2d(
line_1.plotter(t_2=30),
line_2.plotter(t_2=30),
point_1.plotter(c='k'),
point_2.plotter(c='k'),
point_12.plotter(s=75, zorder=3, c='red'),
)
_ = ax.axis('equal')
Lines have opposite direction, but somehow intersect:
line_1.intersect_line(line_2)
# (~28.6, ~0)
>>> Point([2.86362533e+01, 5.26039439e-15])
Hi!
The Line
object is meant to be an infinite line. Instead, the LineSegment
is defined by two endpoints.
But they still looking at different sides of infinite plane, they should never met, aren't they?
From the plot you showed above, the blue line intersects with the orange line at the large red dot. You can change the plot so the blue line extends further, which will make it visually clearer that the lines intersect.
yes, if we assume that when line hit left border of a plane, will continue from the right border, which is not euclidian behavior, imho.
These are infinite 2D lines on the infinite 2D plane. There's no "border" of the plane.
So, your Lines are infinite on both sides, like, to the left of the dot and to the right of the dot.
And intersection above are actually something like this:
And, line_2.plotter(t_2=30)
plots a "ray" because it has t_2
but not t_1
?
No t_1, t_2:
And only manually selecting t_1=-40, t_2=30 I was able to get representative plot:
So yes, this is not intersection calculation problem, but strange behavior of plotting function