Exemplo n.º 1
0
"""
Triangle with Altitudes and Orthocenter
=======================================

Plotting a triangle with its three altitudes and their intersection point, the orthocenter.

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

triangle = Triangle([0, 0], [2, 0], [1, 2])

plot_2d(
    triangle.plotter(c='k', zorder=3),
    triangle.orthocenter().plotter(c='r', edgecolor='k', s=100, zorder=3),
    *[x.plotter(c='k', zorder=3) for x in triangle.multiple('line', 'abc')],
    *[x.plotter() for x in triangle.multiple('altitude', 'ABC')],
)
Exemplo n.º 2
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),
)
Exemplo n.º 3
0
"""
2D Line of Best Fit
===================

Fit a line to multiple 2D points.

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

points = Points([
    [0, 0],
    [0, 1],
    [1, 2],
    [3, 3],
    [4, 3],
    [6, 5],
    [5, 6],
    [7, 8],
])

line_fit = Line.best_fit(points)

plot_2d(
    line_fit.plotter(t_1=-7, t_2=7, c='k'),
    points.plotter(c='k'),
)
Exemplo n.º 4
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')
Exemplo n.º 5
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')
Exemplo n.º 6
0
"""
2D Vector-Vector Projection
===========================

Project a vector onto another vector.

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

vector_a = Vector([1, 1])
vector_b = Vector([2, 0])

vector_projected = vector_b.project_vector(vector_a)

_, ax = plot_2d(
    vector_a.plotter(color='k', head_width=0.1),
    vector_b.plotter(color='k', head_width=0.1),
    vector_projected.plotter(color='r', head_width=0.1),
)

ax.axis([-0.5, 2.5, -0.5, 1.5])