Example #1
0
"""
3D Line-Line Intersection
=========================

"""
from skspatial.objects import Line
from skspatial.plotting import plot_3d


line_a = Line(point=[0, 0, 0], direction=[1, 1, 1])
line_b = Line(point=[1, 1, 0], direction=[-1, -1, 1])

point_intersection = line_a.intersect_line(line_b)


plot_3d(
    line_a.plotter(),
    line_b.plotter(),
    point_intersection.plotter(c='k', s=75),
)
Example #2
0
"""
Sphere-Line Intersection
========================

"""
from skspatial.objects import Sphere, Line
from skspatial.plotting import plot_3d


sphere = Sphere([0, 0, 0], 1)
line = Line([0, 0, 0], [1, 1, 1])

point_a, point_b = sphere.intersect_line(line)


plot_3d(
    line.plotter(t_1=-1, c='k'),
    sphere.plotter(alpha=0.2),
    point_a.plotter(c='r', s=100),
    point_b.plotter(c='r', s=100),
)
Example #3
0
"""
3D Vector-Line Projection
=========================

Project a vector onto a line.

"""
from skspatial.objects import Vector, Line
from skspatial.plotting import plot_3d

line = Line([0, 0, 0], [1, 1, 2])
vector = Vector([1, 1, 0.1])

vector_projected = line.project_vector(vector)

plot_3d(
    line.plotter(t_1=-1, c='k', linestyle='--'),
    vector.plotter(point=line.point, color='k'),
    vector_projected.plotter(point=line.point,
                             color='r',
                             linewidth=2,
                             zorder=3),
)
Example #4
0
"""
Plane-Line Intersection
=======================

"""
from skspatial.objects import Line, Plane
from skspatial.plotting import plot_3d

plane = Plane(point=[0, 0, 0], normal=[1, 1, 1])
line = Line(point=[-1, -1, 0], direction=[0, 0, 1])

point_intersection = plane.intersect_line(line)

plot_3d(
    plane.plotter(lims_x=[-2, 2], lims_y=[-2, 2], alpha=0.2),
    line.plotter(t_2=5),
    point_intersection.plotter(c='k', s=75),
)
Example #5
0
"""
2D Line-Line Intersection
=========================

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


line_a = Line(point=[0, 0], direction=[1, 1.5])
line_b = Line(point=[5, 0], direction=[-1, 1])

point_intersection = line_a.intersect_line(line_b)


plot_2d(
    line_a.plotter(t_1=3),
    line_b.plotter(t_1=4),
    point_intersection.plotter(c='k', s=75, zorder=3),
)
Example #6
0
"""
Circle-Line Intersection
========================

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

circle = Circle([0, 0], 5)
line = Line([0, 0], [1, 1])

point_a, point_b = circle.intersect_line(line)

_, ax = plot_2d(
    circle.plotter(fill=False),
    line.plotter(t_1=-5, t_2=5, c='k'),
    point_a.plotter(c='r', s=100, edgecolor='k', zorder=3),
    point_b.plotter(c='r', s=100, edgecolor='k', zorder=3),
)

ax.axis('equal')
Example #7
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')