Exemplo n.º 1
0
def fit_plane_scipy(P=None):
    from skspatial.objects import Points, Plane
    from skspatial.plotting import plot_3d

    points = Points([[0, 0, 0], [1, 3, 5], [-5, 6, 3], [3, 6, 7], [-2, 6, 7]
                     ]) if P is None else Points(P)

    plane = Plane.best_fit(points)
    plot_3d(
        points.plotter(c='k', s=0.1, depthshade=False),
        plane.plotter(alpha=0.8, lims_x=(-5, 5), lims_y=(-5, 5)),
    )
    plt.show()
Exemplo n.º 2
0
"""
3D Line of Best Fit
===================

Fit a line to multiple 3D points.

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

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

line_fit = Line.best_fit(points)

plot_3d(
    line_fit.plotter(t_1=-7, t_2=7, c='k'),
    points.plotter(c='b', depthshade=False),
)
Exemplo n.º 3
0
"""
3D Plane of Best Fit
====================

Fit a plane to multiple 3D points.

"""
from skspatial.objects import Plane
from skspatial.objects import Points
from skspatial.plotting import plot_3d


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

plane = Plane.best_fit(points)


plot_3d(
    points.plotter(c='k', s=50, depthshade=False),
    plane.plotter(alpha=0.2, lims_x=(-5, 5), lims_y=(-5, 5)),
)
Exemplo n.º 4
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),
)
Exemplo n.º 5
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),
)
Exemplo n.º 6
0
"""
Vector-Plane Projection
=======================

Project a vector onto a plane.

"""
from skspatial.objects import Plane
from skspatial.objects import Vector
from skspatial.plotting import plot_3d

plane = Plane([0, 0, 0], [0, 0, 1])
vector = Vector([1, 1, 1])

vector_projected = plane.project_vector(vector)

_, ax = plot_3d(
    plane.plotter(lims_x=(-5, 5), lims_y=(-5, 5), alpha=0.3),
    vector.plotter(point=plane.point, color='k'),
    vector_projected.plotter(point=plane.point,
                             color='r',
                             linewidth=2,
                             zorder=3),
)

ax.set_zlim([-1, 1])
Exemplo n.º 7
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),
)
Exemplo n.º 8
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),
)
Exemplo n.º 9
0
cordi_after = np.zeros_like(cordi)

for i in range(len(cordi)):
    point_tem = plane.project_point(cordi[i])
    cordi_after[i] = np.array(point_tem)

# print(cordi_after)

points_after = Points(cordi_after)

# print(points)
# print(type(points))

plot_3d(
    points_after.plotter(c='k', s=5, depthshade=False),
    plane.plotter(alpha=0.2, lims_x=(-1, 1), lims_y=(-1, 1)),
)

# fig = plt.figure()
# ax = Axes3D(fig)
# ax.scatter(cordi[:, 0], cordi[:, 1], cordi[:, 2])
# plt.show()


def rotation(normal_vector_, support_vector):
    a = np.array(normal_vector_)
    b = np.array(support_vector)
    theta_ = np.arccos(np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b)))

    rotation_axis = np.cross(a, b)
Exemplo n.º 10
0
"""
Point-Plane Projection
======================

Project a point onto a plane.

"""
from skspatial.objects import Plane
from skspatial.objects import Point
from skspatial.objects import Vector
from skspatial.plotting import plot_3d


plane = Plane(point=[0, 0, 2], normal=[1, 0, 2])
point = Point([5, 9, 3])

point_projected = plane.project_point(point)
vector_projection = Vector.from_points(point, point_projected)


plot_3d(
    plane.plotter(lims_x=(0, 10), lims_y=(0, 15), alpha=0.3),
    point.plotter(s=75, c='k'),
    point_projected.plotter(c='r', s=75, zorder=3),
    vector_projection.plotter(point=point, c='k', linestyle='--'),
)
Exemplo n.º 11
0
"""
Plane-Plane Intersection
========================

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

plane_a = Plane([0, 0, 0], [1, 0, 0])
plane_b = Plane([0, 0, 0], [1, 0, 1])

line_intersection = plane_a.intersect_plane(plane_b)

plot_3d(
    plane_a.plotter(alpha=0.2),
    plane_b.plotter(alpha=0.2),
    line_intersection.plotter(t_1=-1, c='k'),
)