Giter Club home page Giter Club logo

catrom's Introduction

CatRom logo CatRom logo

Creates Catmull-Rom splines.

The Catmull-Rom spline (CatRom) is a cousin of the popular Bézier curve, with the key difference that CatRoms are guaranteed to pass through their control points. This allows them to chain together predictably and intuitively.

How to use

The CatRom constructor takes 3 arguments:

  1. points: An array of Vector2s, Vector3s, or CFrames.
  2. alpha [optional]: A number (usually) in [0, 1] that determines the "parameterization" of the spline; defaults to 0.5.
  3. tension [optional]: A number (usually) in [0, 1] that determines how loose the spline is; defaults to 0.

The default alpha of 0.5 is the only way to avoid cusps and loops, as shown in this paper.

API

Note: For each Solve method, there exists a SolveUniform counterpart that spaces the input(s) uniformly along the curve. Be aware that the uniform methods are slower to compute.

CatRom.new(points: array, alpha: number?, tension: number?)
CatRom:SolvePosition(t: number)
CatRom:SolveCFrame(t: number)
CatRom:SolveRotCFrame(t: number)
CatRom:SolveVelocity(t: number)
CatRom:SolveAcceleration(t: number)
CatRom:SolveTangent(t: number)
CatRom:SolveNormal(t: number)
CatRom:SolveBinormal(t: number)
CatRom:SolveCurvature(t: number)
CatRom:SolveLength(a: number?, b: number?)
CatRom:PrecomputeArcLengthParams(numIntervals: number?)

Performance Tips

1. Uniform methods

If you are calling many Uniform methods, you should call PrecomputeArcLengthParams() immediately after construction. This will make your Uniform calls less accurate but cheaper to compute. The accuracy can be further tuned using the numIntervals argument; lower is faster and less accurate, higher is slower and more accurate (defaults to 16).

2. Repeated inputs

If you are calling many methods on the same input like so:

local t -- number in [0, 1]
local catRom -- a CatRom object
catRom:SolvePosition(t)
catRom:SolveVelocity(t)
catRom:SolveTangent(t)

then it is faster to instead do

local t -- number in [0, 1]
local catRom -- a CatRom object
local spline, splineT = catRom:GetSplineFromT(t)
spline:SolvePosition(splineT)
spline:SolveVelocity(splineT)
spline:SolveTangent(splineT)

catrom's People

Contributors

ecurtiss avatar hasnain123raza avatar

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.