搜索插件、代码仓与 APP 分类

插件详情v1.2.0

bezier

一个2D贝塞尔曲线数学库。大量借鉴了@TheRealPomax 的工作。实时示例可在 . 找到。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
8820
喜欢数
58
Pub 分数
150

安装插件

flutter pub add bezier

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个用于 Dart 的 2D 贝塞尔曲线数学库,专为精确的曲线计算和操作而设计。基于 @TheRealPomax 的基础工作,提供了强大的工具来生成、评估和分析贝塞尔曲线。非常适合在 Flutter 应用中用于图形、动画和路径生成。该库支持所有主要平台,并包含实时示例以供演示。它轻量且专注于数学准确性。

适合场景

  • UI 中的路径动画
  • 为绘图生成平滑曲线
  • 在图形中创建自定义形状
  • 点之间的插值
  • 设计基于矢量的动画
  • 实现基于曲线的运动

主要特点

  • 精确的2D贝塞尔数学
  • 支持多种曲线类型
  • 在任意参数 t 处的评估
  • 曲线细分功能
  • 平台无关的实现
  • 实时示例集成

适合对象

  • Flutter 开发人员使用动画
  • 需要平滑路径的UI设计师
  • 图形和可视化项目
  • 数学密集型应用逻辑
  • 曲线理论的教育工具
  • 带有曲线移动的游戏开发

使用建议

  • 不适用于3D曲线
  • 需要理解贝塞尔数学
  • 仅限基本曲线操作
  • 无内置渲染支持
  • 最好与图形图层配合使用
  • 依赖外部文档以进行高级使用

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

bezier.dart is a simple open-source Dart library for handling 2D Bézier curve math.

The library was developed, documented, and published by Aaron Barrett and Isaac Barrett. It is based heavily on the work of Pomax, including his excellent Primer on Bézier Curves and his original JavaScript library, Bezier.js.

We're trying to design bezier.dart to be both platform independent and context independent. You can run the library anywhere you can run Dart: in a web browser, in a Flutter application, server side, and beyond.

For live examples of the library's API, see the project page at dartographer.com/bezier.

Features

  • Supports both quadratic and cubic two dimensional Bézier curves
  • Calculate the coordinates of a point at any parameter value t along a curve
  • Derivative and normal values at any t parameter value
  • Accurate length approximations (using the Legendre-Gauss quadrature algorithm)
  • Split a curve into equivalent subcurves between any t parameter values
  • Find the extrema of a curve on both the x and y axes
  • Calculate the bounding box for a curve
  • Given any curve, derive a new curve, offset from the original curve along the normals at a given distance
  • Calculate the positions of a curve's intersections with itself, with another curve, or with a line segment
  • Find points evenly spaced along the arc length of a curve
  • Heavily documented and tested
  • Straightforward, readable code

Getting Started

  1. Add the following to your project's pubspec.yaml and run pub get.
dependencies:
  bezier: any
  1. Import bezier.dart from a file in your project. In most cases you will also want to import the vector_math library.
import "package:vector_math/vector_math.dart";
import "package:bezier/bezier.dart";

Examples

  • Instantiate a Bézier curve.
import "package:vector_math/vector_math.dart";
import "package:bezier/bezier.dart";

void main() {
  // bezier.dart supports both quadratic curves...
  final quadraticCurve = QuadraticBezier([
    Vector2(-40.0, -40.0),
    Vector2(30.0, 10.0),
    Vector2(55.0, 25.0)
  ]);

  // ...and cubic curves!
  final cubicCurve = CubicBezier([
    Vector2(10.0, 10.0),
    Vector2(70.0, 95.0),
    Vector2(25.0, 20.0),
    Vector2(15.0, 80.0)
  ]);
}
  • Compute a point along a curve at t of 0.75.
import "package:vector_math/vector_math.dart";
import "package:bezier/bezier.dart";

void main() {
  final curve = QuadraticBezier([
    Vector2(10.0, 10.0),
    Vector2(70.0, 95.0),
    Vector2(15.0, 80.0)
  ]);

  final computedPoint = curve.pointAt(0.75);
}
  • Split a curve between the t parameter values of 0.2 and 0.6.
import "package:vector_math/vector_math.dart";
import "package:bezier/bezier.dart";

void main() {
  final curve = CubicBezier([
    Vector2(10.0, 10.0),
    Vector2(70.0, 95.0),
    Vector2(25.0, 20.0),
    Vector2(15.0, 80.0)
  ]);

  final subcurve = curve.subcurveBetween(0.2, 0.6);
}
  • Find the intersection t values between a curve and a line segment.
import "package:vector_math/vector_math.dart";
import "package:bezier/bezier.dart";

void main() {
  final curve = QuadraticBezier([
    Vector2(10.0, 500.0),
    Vector2(50.0, 0.0),
    Vector2(90.0, 500.0)
  ]);

  final lineStart = Vector2(0.0, 400.0);
  final lineEnd = Vector2(100.0, 410.0);

  final intersections = curve.intersectionsWithLineSegment(lineStart, lineEnd);
}
  • Derive an offset curve (composed of a series of subcurves) at distance 12.0.
import "package:vector_math/vector_math.dart";
import "package:bezier/bezier.dart";

void main() {
  final curve = CubicBezier([
    Vector2(10.0, 10.0),
    Vector2(15.0, 95.0),
    Vector2(20.0, 95.0),
    Vector2(25.0, 10.0)
  ]);

  final subcurves = curve.offsetCurve(12.0);
}

Style, Formatting, Philosophy

We've made our best effort to conform to the recommendations outlined in the Effective Dart guide. Accordingly, this library is formatted using dartfmt.

As fervent believers in the value of clean code, we are constantly seeking to improve the library and make it easier to work with. Please alert us to any issues you notice, no matter how trivial. We wholeheartedly welcome criticism and friendly debate! :nerd_face:

Running Automated Tests

To run the test cases from the terminal, run the following command from the bezier.dart root directory.

pub run test

Most IDEs now provide interfaces for running tests, which are generally easier to work with. In most cases you can simply right click on a test file or directory in the project tree view and select the menu option to run the selected tests.

Submitting bugs, requesting features

Please file feature requests and bugs using the GitHub issues tab.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目