패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.2.0

bezier

2D 베지에 곡선 수학 라이브러리입니다. @TheRealPomax의 작업을 크게 참고했습니다. 실시간 예제는 . 에서 확인할 수 있습니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
8.8천
좋아요
58
Pub 점수
150

패키지 설치

flutter pub add bezier

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

정밀한 곡선 계산과 조작을 위한 Dart용 2D 베지어 곡선 수학 라이브러리입니다. @TheRealPomax의 기초 작업을 바탕으로, 베지어 곡선의 생성, 평가 및 분석을 위한 강력한 도구를 제공합니다. Flutter 애플리케이션에서 그래픽, 애니메이션 및 경로 생성에 이상적입니다. 모든 주요 플랫폼을 지원하며, 시연을 위한 실시간 예제도 포함되어 있습니다. 가볍고 수학적 정확성에 집중된 라이브러리입니다.

사용 사례

  • UI에서 경로 애니메이션
  • 그림을 위한 부드러운 곡선 생성
  • 그래픽에서 사용자 정의 모양 만들기
  • 점 사이의 보간
  • 벡터 기반 애니메이션 설계
  • 곡선 기반 운동 구현

주요 기능

  • 정확한 2차 베지어 수학
  • 다양한 곡선 유형 지원
  • 임의의 매개변수 t에서의 평가
  • 곡선 분할 기능
  • 플랫폼에 관계없는 구현
  • 실시간 예제 통합

적합한 대상

  • 애니메이션을 사용하는 플러터 개발자
  • 부드러운 경로가 필요한 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 개

소스 저장소

이 패키지를 사용하는 프로젝트