bezier curve使用

安装

python -m pip install --upgrade bezier

网址

https://pypi.org/project/bezier/

例子

For example, to create a curve:

import numpy as np
import bezier
nodes1=np.asfortranarray([[0.0,0.5,1.0],[0.0,1.0,0.0]])
curve1=bezier.Curve(nodes1,degree=2)
curve1=bezier.Curve(nodes1,degree=2)
nodes2=np.asfortranarray([[0.0,0.25,0.5,0.75,1.0],[0.0,2.0,-2.0,2.0,0.0]])
curve2=bezier.Curve(nodes2,degree=2)
intersections=curve1.intersect(curve2)
s_vals=np.asfortranarray(intersections[0,:])
points=curve1.evaluate_multi(s_vals)

import matplotlib.pyplot as plt
import seaborn
seaborn.set()
ax=curve1.plot(num_pts=256)
_=curve2.plot(num_pts=256,ax=ax)
line=ax.plot(points[0,:],points[1,:],marker='o',linestyle='none',color='black')
_=ax.axis('scaled')
_=ax.set_xlim(-0.125,1.125)
_=ax.set_ylim(-0.125,1.125)
plt.show()

nodes1 = np.asfortranarray([
… [0.0, 0.5, 1.0],
… [0.0, 1.0, 0.0],
… ])

curve1 = bezier.Curve(nodes1, degree=2)

The intersection (points) between two curves can also be determined:

nodes2 = np.asfortranarray([
… [0.0, 0.25, 0.5, 0.75, 1.0],
… [0.0, 2.0 , -2.0, 2.0 , 0.0],
… ])

curve2 = bezier.Curve.from_nodes(nodes2)
intersections = curve1.intersect(curve2)
intersections
array([[0.31101776, 0.68898224, 0. , 1. ],
[0.31101776, 0.68898224, 0. , 1. ]])

s_vals = np.asfortranarray(intersections[0, :])
points = curve1.evaluate_multi(s_vals)
points
array([[0.31101776, 0.68898224, 0. , 1. ],
[0.42857143, 0.42857143, 0. , 0. ]])
and then we can plot these curves (along with their intersections):

import matplotlib.pyplot as plt
import seaborn
seaborn.set()

ax = curve1.plot(num_pts=256)
_ = curve2.plot(num_pts=256, ax=ax)
lines = ax.plot(
… points[0, :], points[1, :],
… marker=‘o’, linestyle=‘None’, color=‘black’)

_ = ax.axis(‘scaled’)
_ = ax.set_xlim(-0.125, 1.125)
_ = ax.set_ylim(-0.0625, 0.625)
plt.show()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值