예제 #1
0
def test_project_point_line(point, point_line, vector_line, point_expected,
                            dist_expected):
    line = Line(point_line, vector_line)

    point_projected = line.project_point(point)
    distance = line.distance_point(point)

    assert point_projected.is_close(point_expected)
    assert math.isclose(distance, dist_expected)
예제 #2
0
def project_on_vector(L, R, M):
    '''gets left and closest Right and measured points, returns projection on the vector btw. R&L of M'''
    line = Line(point = L[0:2], direction=R[0:2])
    point = Point(M[0:2])

    line_const = line2pts(L, R)

    point_projected = line.project_point(point)
    line_projection = Line.from_points(point, point_projected)

    result = {"Point" : point_projected,
              "Line" : line_projection,
              "Distance": distance_pt2line(line_const["m"], line_const["b"], M[0:2])}
    return result
예제 #3
0
"""
2D Point-Line Projection
========================

Project a point onto a line.

"""
from skspatial.objects import Point, Line
from skspatial.plotting import plot_2d

line = Line(point=[0, 0], direction=[1, 1])
point = Point([1, 4])

point_projected = line.project_point(point)
line_projection = Line.from_points(point, point_projected)

_, ax = plot_2d(
    line.plotter(t_2=5, c='k'),
    line_projection.plotter(c='k', linestyle='--'),
    point.plotter(s=75, c='k'),
    point_projected.plotter(c='r', s=75, zorder=3),
)

ax.axis('equal')