1.手写bezier公式,生成bezier代码, 如果给的点数过多,则会生成一半bezier曲线,剩下的一半就需要进行拼接:

 import numpy as np
import matplotlib.pyplot as plt
import bezier
b_xs = []
b_ys = [] # xs表示原始数据
# n表示阶数
# k表示索引
def one_bezier_curve(a, b, t):
return (1 - t) * a + t * b def n_bezier_curve(xs, n, k, t):
if n == 1:
return one_bezier_curve(xs[k], xs[k + 1], t)
else:
return (1 - t) * n_bezier_curve(xs, n - 1, k, t) + t * n_bezier_curve(xs, n - 1, k + 1, t) def bezier_curve(xs, ys, num, b_xs, b_ys):
n = 5 # 采用5次bezier曲线拟合
t_step = 1.0 / (num - 1)
# t_step = 1.0 / num
print(t_step)
t = np.arange(0.0, 1 + t_step, t_step)
print(len(t))
for each in t:
b_xs.append(n_bezier_curve(xs, n, 0, each))
b_ys.append(n_bezier_curve(ys, n, 0, each)) def func():
xs = [1.0, 2.1, 3.0, 4.0, 5.0, 6.0]
ys = [0, 1.1, 2.1, 1.0, 0.2, 0]
num = 20 bezier_curve(xs, ys, num, b_xs, b_ys) # 将计算结果加入到列表中
print(b_xs, b_ys)
plt.figure()
plt.plot(b_xs, b_ys, 'r') # bezier曲线
# plt.plot(xs, ys) # 原曲线
# plt.show() func()

2. 拼接bezier曲线

def point_bezier(avoid_point):
global p
xs = avoid_point[0, 0] #
ys = avoid_point[1, 0] #
xe = avoid_point[0, -1] # 34.5844
ye = avoid_point[1, -1] #
Latoff = 2.3
startp = np.array([xs, ys])
endp = np.array([xe, ye])
endp1 = np.array([xe+2, ye])
# print(startp, endp)
P0 = startp
P1 = np.array([startp[0] + (endp[0] - startp[0]) / 8, startp[1]])
P2 = np.array([startp[0] + (endp[0] - startp[0]) / 8 * 2, startp[1]])
P3 = np.array([startp[0] + (endp[0] - startp[0]) / 8 * 2, startp[1] + Latoff])
P4 = np.array([startp[0] + (endp[0] - startp[0]) / 8 * 3, startp[1] + Latoff])
P5 = np.array([startp[0] + (endp[0] - startp[0]) / 8 * 4, startp[1] + Latoff])
P6 = np.array([startp[0] + (endp[0] - startp[0]) / 8 * 5, startp[1] + Latoff])
P7 = np.array([startp[0] + (endp[0] - startp[0]) / 8 * 6, startp[1] + Latoff])
P8 = np.array([startp[0] + (endp[0] - startp[0]) / 8 * 6, startp[1] + Latoff])
P9 = np.array([startp[0] + (endp[0] - startp[0]) / 8 * 7, startp[1]])
P10 = endp
P11 = endp1
i = 1
half_length = 0.5 * (xe + xs)
for u in np.arange(startp[0], startp[0] + (endp[0] - startp[0]) / 2, 0.2):
# for u =startp[0]:0.2: startp[1] + (endp[1] - startp[1]) / 2
c = (1 - (u - startp[0]) / half_length) ** 5 * P0 + 5 * (1 - (u - startp[0]) / half_length) ** 4 * (
u - startp[0]) / half_length * P1 + 10 * (1 - (u - startp[0]) / half_length) ** 3 * (
(u - startp[0]) / half_length) ** 2 * P2 + 10 * (1 - (u - startp[0]) / half_length) ** 2 * (
(u - startp[0]) / half_length) ** 3 * P3 + 5 * (1 - (u - startp[0]) / half_length) * (
(u - startp[0]) / half_length) ** 4 * P4 + ((u - startp[0]) / half_length) ** 5 * P5
i = i + 1
p = np.append(p, [c], axis=0) for u in np.arange(startp[0] + half_length, endp[0], 0.2):
d = (1 - (u - startp[0] - half_length) / half_length) ** 5 * P6 + 5 * (
1 - (u - startp[0] - half_length) / half_length) ** 4 * (
u - startp[0] - half_length) / half_length * P7 + 10 * (
1 - (u - startp[0] - half_length) / half_length) ** 3 * (
(u - startp[0] - half_length) / half_length) ** 2 * P8 + 10 * (
1 - (u - startp[0] - half_length) / half_length) ** 2 * (
(u - startp[0] - half_length) / half_length) ** 3 * P9 + 5 * (
1 - (u - startp[0] - half_length) / half_length) * (
(u - startp[0] - half_length) / half_length) ** 4 * P10 + (
(u - startp[0] - half_length) / half_length) ** 5 * P11
i = i + 1
p = np.append(p, [d], axis=0)
return p
# print(p)
# plt.plot(p[:, 0], p[:, 1], 'r')
# plt.show()

3.使用python 内置bezier包,完成bezier曲线(使用前需安装bezier包)

 a = np.array([[1.0, 2.1, 3.0, 4.0, 5.0, 6.0], [0, 1.1, 2.1, 1.0, 0.2, 0]])
curve = bezier.Curve(a, degree=5)
# print(curve)
s_vals = np.linspace(0.0, 1.0, 30)
data = curve.evaluate_multi(s_vals)
x33 = data[0]
y33 = data[1]
plt.plot(x33, y33, 'y', linewidth=2.0, linestyle="-", label="y2")
plt.show()

python bezier 曲线的更多相关文章

  1. Bezier曲线的原理 及 二次Bezier曲线的实现

    原文地址:http://blog.csdn.net/jimi36/article/details/7792103 Bezier曲线的原理 Bezier曲线是应用于二维图形的曲线.曲线由顶点和控制点组成 ...

  2. [摘抄] Bezier曲线、B样条和NURBS

    Bezier曲线.B样条和NURBS,NURBS是Non-Uniform Rational B-Splines的缩写,都是根据控制点来生成曲线的,那么他们有什么区别了?简单来说,就是: Bezier曲 ...

  3. C# 实现Bezier曲线(vs2008)

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  4. 连续bezier曲线的实现

    需求场景 一系列的坐标点,划出一条平滑的曲线 3次Bezier曲线 基本上大部分绘图工具都实现了3次Bezier曲线,4个点确定一条3次Bezier曲线.以html5中的canvas为例 let ct ...

  5. 7.5.5编程实例-Bezier曲线曲面绘制

    (a)Bezier曲线                         (b) Bezier曲面 1. 绘制Bezier曲线 #include <GL/glut.h> GLfloat ct ...

  6. 实验6 Bezier曲线生成

    1.实验目的: 了解曲线的生成原理,掌握几种常见的曲线生成算法,利用VC+OpenGL实现Bezier曲线生成算法. 2.实验内容: (1) 结合示范代码了解曲线生成原理与算法实现,尤其是Bezier ...

  7. 简单而粗暴的方法画任意阶数Bezier曲线

    简单而粗暴的方法画任意阶数Bezier曲线 虽然说是任意阶数,但是嘞,算法原理是可以到任意阶数,计算机大概到100多阶就会溢出了 Bezier曲线介绍] [本文代码] 背景 在windows的Open ...

  8. iOS Bezier曲线

    https://www.jianshu.com/p/2316f0d9db65 1. Bezier曲线 相关软件:PaintCode:可以直接画图,软件根据图像生产Bezier曲线 相关概念:UIBez ...

  9. Bezier曲线的实现——de Casteljau算法

    这学期同时上了计算机图形学和计算方法两门课,学到这部分的时候突然觉得de Casteljau递推算法特别像牛顿插值,尤其递推计算步骤很像牛顿差商表. 一开始用伯恩斯坦多项式计算Bezier曲线的时候, ...

随机推荐

  1. BZOJ5415 [NOI2018] 归程

    今天也要踏上归程了呢~(题外话 kruskal重构树!当时就听学长们说过是重构树辣所以做起来也很快233 就是我们按照a建最大生成树 这样话呢我们就可以通过生成树走到尽量多的点啦 然后呢就是从这个子树 ...

  2. 纯JSP简单登录实例

    记一下,免得以后忘记了,又要去查. 文件共有四个web.xml.login.jsp.logout.jsp.welcome.jsp四个文件 测试环境:Tomcat 6.0.x 假设项目名称是LoginS ...

  3. python不能运行

    运行python文件出现,报错please select a valid interpreter 这是因为没有选择interpreter  就是更改目录时需要重新选择pytho解析器 解决方法如下 更 ...

  4. HDU 6038 Function —— 2017 Multi-University Training 1

    Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total ...

  5. PHP 常用自定义函数

    模拟 POST.GET 请求 /** * 模拟post进行url请求 * @param string $url * @param string $param */ protected function ...

  6. (三)修改内核大小,适配目标板Nand flash分区配置

    一. 修改内核大小 1. 在你的配置文件下uboot/include/config/xxx.h 里面有一个宏定义 #define MTDPARTS_DEFAULT "mtdparts=jz2 ...

  7. drf:restful概念,类继承关系,drf请求封装,drf请求流程,版本控制组件,认证组件(token),权限组件

    1.restful规范 resfful规范的概念最重要: 是一套规范,规则,用于程序之间进行数据交换的约定. 他规定了一些协议,对我们感受最直接的就是,以前写增删改查的时候需要些四个视图寒素,rest ...

  8. appium常见问题03_appium脚本报错selenium.common.exceptions.WebDriverException

    运行appium脚本时报错selenium.common.exceptions.WebDriverException...,如下截图: 该报错说明appium和app的内置chrome版本不一致 [解 ...

  9. Cocos2d-x之MessageBox

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 在cocos2d-x中使用的对话框为MessageBox,因为cocos2d-x已经包装好了:但是在一般的游戏设置中,我们不会使用coco ...

  10. bitset归结,一个实例

    我是蒟蒻一名,请大佬勿喷. 绝大部分来自https://www.cnblogs.com/magisk/p/8809922.html   ,  可以去大佬博客逛一逛 bitset是C++中类似数组的一种 ...