Beispiel #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()
Beispiel #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),
)
Beispiel #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)),
)
Beispiel #4
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)
Beispiel #5
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'),
)