跳转至

命令行界面

安装 cli 可选依赖后即可使用 bezierkit 命令,在命令行计算、采样与构造曲线。默认输出表格,也可输出 JSON 或 CSV 给其他程序使用。

bezierkit evaluate --points "0,0" --points "1,2" --points "3,2" --points "4,0" \
                   --t 0.5 --order 1 --json
# [{"t":0.5,"value":[4.5,0.0]}]

控制点

需要曲线的命令以重复的 --points 选项接收控制点,每个是以逗号分隔的坐标("1,2",三维则为 "1,2,3")。省略 --points 时,命令从标准输入读取含 control_points 数组的 JSON 对象,也就是 construct 的输出,因此命令之间可以用管道串接。

命令

bezierkit evaluate --t values [--points ...] [--order int] [--json]

在每个 --t 计算曲线值,或其 --order 阶导数(默认 0)。每个值可为数字或含端点的范围 start:stop:step,例如 0:1:0.25;--t 可重复。

bezierkit sample [--points ...] [--count int] [--format table|csv|json] [--output path]

以 --count 个(默认 50)等距参数采样,含两端,每列为 t、x、y(三维另有 z,更高维为 c3、c4……)。--output 写入文件而非标准输出。

bezierkit construct slopes --start point --end point --start-slope float --end-slope float [--start-handle --end-handle]
bezierkit construct tangents --start ... --end ... --start-direction vector --end-direction vector [...]

以 PlanarSlopes 或 TangentDirections(详见建构与 Hermite 插值)构造三次曲线,并以 JSON 打印控制点。

bezierkit construct slopes --start "0,5" --end "5,0" \
                           --start-slope -2 --end-slope -0.3 \
| bezierkit sample --count 3 --format csv
# t,x,y
# 0.0,0.0,5.0
# 0.5,2.3085202413545525,2.272345260462411
# 1.0,5.0,0.0

错误

无效输入(例如格式错误的点,或超出 \([0, 1]\) 的参数)会在标准错误输出打印 Error: ...,退出状态为 1,不显示 traceback。在命令前加上全域选项 --debug 可改为显示 Python traceback。

评论