搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案