scikit-spatial学习记录——projection

Example Gallery — scikit-spatial documentationhttps://scikit-spatial.readthedocs.io/en/stable/gallery/index.htmlhttps://scikit-spatial.readthedocs.io/en/stable/gallery/index.htmlhttps://scikit-spatial.readthedocs.io/en/stable/gallery/index.htmlhttps://scikit-spatial.readthedocs.io/en/stable/gallery/index.html1、2D Vector-Vector Projection

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)
#  向量a投影到向量b,返回向量

_, 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])  #  显示的坐标轴坐标

2、line-Plane Projection

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

plane = Plane([0, 1, 0], [0, 1, 0])   #  plane(点,法向量)
line = Line([0, -1, 0], [1, -2, 0])   #  line(点,方向)

line_projected = plane.project_line(line)   #  线投到面上


plot_3d(
    plane.plotter(lims_x=(-5, 5), lims_y=(-5, 5), alpha=0.3),
    line.plotter(t_1=-2, t_2=2, color='k'),
    line_projected.plotter(t_1=-2, t_2=4, color='r'),
)

3、3D Vector-Line Projection

from skspatial.objects import Line
from skspatial.objects import Vector
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),
)

 

4、Vector-Plane Projection

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])

5、2D Point-Line Projection

from skspatial.objects import Line
from skspatial.objects import Point
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')

6、Point-Plane Projection

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='--'),
)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值