Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Curve

Brief

Curve represents a parametrized curve in an arbitrary affine space.

Main features

  • LIFO of vectors push, pop
  • linear interpolation of position, speed, length
  • manipulate origin of the curve origin
  • geometrical transforms translate, affine, ...

Getting started

A curve is a discrete set of Vector objects that describes a polygonal curve in ND-space. It has an origin that is common to all points. The curve can be parametrized with different speeds along it.

Curve diagram

Create a curve

First create a set of vectors that represents the polygonal curve and a choose a time step.

let positions = [Vector3.ex, Vector3.ey, Vector3.exn, Vector3.eyn];
let dt = 0.1;

If you want to set a variable time step along the curve you can specify dt as an array

let dt = [0.1, 0.01, 1];

Note If positions is of size N then dt is of size N-1.

Then choose your origin and construct the curve :

const origin = Vector3.zeros
let curve = new Curve(positions, origin, dt); // origin is (0, 0, 0)

Note It's preferable that the origin does not reference an object contained in the positions array and that references in positions points to different instances.

Positions

The positions array stores position of curve samples relative to this.origin, when affecting a new origin, the new relative positions are recomputed. It's the same process as what was done for Point3 class.

LIFO Structure

You can push/pop elements of the curve. When pushing you have to specify the position vector to insert. You can also specify a time step dt which correspond to the duration to perform a displacement from the last stored to the position to insert.

Example

curve.push(Vector3.ez) // push with default value of time step
curve.push(Vector3.ez, 0.1) // push with given value of time step

However when popping a value a couple with duration and position is always returned.

Example

arr = curve.pop() // [u, dt]

Interpolation

As polygonal curves, we can perform linear interpolation between two points of the curve. This allows to get the speed, position and many other values along the curve as if it was a polygonal continuous curve.

All the interpolation functions uses x parameter, a real value between 0 and 1 :

  • x = 0 denotes the starting of the curve
  • x = 1 denotes the ending of the curve
  • x = 0.5 denotes the middle of the curve

Interpolation diagram

Note γ denotes the position vector on the curve according to the parametrization with x.

Example

let u = curve.position(0.5); // middle point of the curve
let v = curve.length(1); // total length of the curve
let w = curve.speed(0); // initial speed of the curve

Translation and Transformation

Apply matrix transform, translations and affine transforms the same way as for Point3 class..

curve.translate(u);
curve.transform(m);
curve.affine(m, u);

2019 samiBendou © All Rights Reserved

Hierarchy

  • Curve

Index

Constructors

constructor

  • explicitly construct a curve by giving, positions, origins and time step(s)

    Parameters

    • Default value positions: Vector[] = []
    • Optional origin: Vector
    • Default value dt: number[] | number = 1

    Returns Curve

Properties

dt

dt: number[]

array of duration elapsed for each displacement between two successive positions. Must be of length position.length - 1.

positions

positions: Vector[]

position vectors representing the curve

Accessors

first

last

nexto

  • position vector of the curve next to last

    Returns Vector

  • position vector of the curve next to last

    Parameters

    Returns void

origin

Methods

affine

clear

  • clear(): this
  • brief

    clears the curve

    details

    Removes all position and steps.

    Returns this

duration

  • duration(x?: number): number
  • brief

    duration on parametrized curve

    details

    It's the total duration to go from position at 0 to position at x according to the parametrization of the curve.

    Parameters

    • Default value x: number = 1

      parameter between 0 and 1

    Returns number

    value of the duration at x

length

  • length(x?: number): number
  • brief

    length on parametrized curve

    details

    It's the total length to go from position at 0 to position at x.

    Parameters

    • Default value x: number = 1

      parameter between 0 and 1

    Returns number

    value of the length at x

pop

position

  • position(x?: number): Vector
  • brief

    position on parametrized curve

    Parameters

    • Default value x: number = 1

      parameter between 0 and 1

    Returns Vector

    value of position at x

push

  • push(position: Vector, dt?: number): this
  • brief

    add a new position to the trajectory

    details

    If you let dt undefined, then the method will take the last added step if it exists.

    Parameters

    • position: Vector

      position vector to insert

    • Optional dt: number

      duration elapsed since last position

    Returns this

speed

  • brief

    speed on parametrized curve

    Parameters

    • Default value x: number = 1

      parameter between 0 and 1

    Returns Vector

    value of position at x

transform

translate

Static graph

  • graph(f: function, a: number, b: number, dt?: number): Curve
  • brief

    generates a curve that is the graph of a function.

    details

    Samples the function f from f(a) to f(b) with constant time step

    Parameters

    • f: function

      vector valued function that depends only on time.

    • a: number

      starting point to evaluate f

    • b: number

      ending point to evaluate f

    • Default value dt: number = 1

      constant time step to sample f

    Returns Curve

Static zeros

  • zeros(u: Vector, size: number, dt?: number[] | number): Curve
  • brief

    generates a constant curve ie. a point.

    details

    The position is constant and the step is non zero

    Parameters

    • u: Vector

      position of the point

    • size: number

      number of samples

    • Default value dt: number[] | number = 1

      time step

    Returns Curve

Generated using TypeDoc