Giter Club home page Giter Club logo

bezier-spline-kotlin's Introduction

bezier-spline-kotlin

A generic multi-order bezier curve and cubic bezier spline implementation for Java/Kotlin.

Maven Central

Note

  • The calculation of bezier curve and spline lengths are implemented using estimation of variable resolution, which should be more than sufficient for most applications. Coordinates and tangents are not affected by this. If you require highly accurate measurements, consider using another library.
  • There might be slightly more performant Java implementations out there. The main focus lies on being as generic as possible.

Bezier Spline with Tangents

Installation

<dependency>
  <groupId>dev.benedikt.math</groupId>
  <artifactId>bezier-spline</artifactId>
  <version>2.0.0</version>
</dependency>

Bezier Spline

Note: Check out the BezierSpline documentation for further options.

You can create open or closed bezier splines for any amount of dimensions using the provided FloatBezierSpline, DoubleBezierSpline and Vector implementations. You may also create a custom bezier spline implementation.

BezierSpline<Double, Vector2D> spline = new DoubleBezierSpline<>(true);

spline.addKnots(
        new Vector2D(0.06, 0.06),
        new Vector2D(0.7, 0.24),
        new Vector2D(0.6, 0.1),
        new Vector2D(0.33, 0.39)
);

double length = spline.getLength();
Vector2D coordinates = spline.getCoordinatesAt(0.5);
Vector2D tangent = spline.getTangentAt(0.5);

The required length estimation happens the first time lengths, coordinates, tangents or control points are queried. You can manually update the spline to move the workload. By default, the performance impact is negligible in most cases.

spline.compute(); // calculations happen here.

// ...

double length = spline.getLength(); // without performance impact
Vector2D coordinates = spline.getCoordinatesAt(0.5);
Vector2D tangent = spline.getTangentAt(0.5);

Bezier Curve

BezierCurve<Double, Vector2D> curve = new DoubleBezierCurve(Order.CUBIC, from, to, controlPoints);

double length = curve.getLength();
Vector2D coordinates = curve.getCoordinatesAt(0.5);
Vector2D tangent = curve.getTangentAt(0.5);

The required length estimation happens the first time the length is queried. You can manually update the curve to move the workload. By default, the performance impact is negligible in most cases.

curve.computeLength(); // calculations happen here.

// ...

double length = curve.getLength(); // without performance impact
Vector2D coordinates = curve.getCoordinatesAt(0.5);
Vector2D tangent = curve.getTangentAt(0.5);

bezier-spline-kotlin's People

Contributors

benedikt-wueller avatar bwuellerlprit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bezier-spline-kotlin's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.