codac 1.5.6
Loading...
Searching...
No Matches
codac::Trajectory Class Reference

One dimensional trajectory \(x(\cdot)\), defined as a temporal map of values. More...

#include <codac_Trajectory.h>

Inheritance diagram for codac::Trajectory:
Collaboration diagram for codac::Trajectory:

Public Member Functions

Definition
 Trajectory ()
 Creates an empty scalar trajectory \(x(\cdot)\).
 
 Trajectory (const Interval &tdomain, const TFunction &f)
 Creates a scalar trajectory \(x(\cdot)\) from an analytic expression.
 
 Trajectory (const Interval &tdomain, const TFunction &f, double timestep)
 Creates a scalar trajectory \(x(\cdot)\) from an analytic expression, and transforms it as a map of values (sampling procedure)
 
 Trajectory (const std::map< double, double > &m_map_values)
 Creates a scalar trajectory \(x(\cdot)\) from a map of values.
 
 Trajectory (const std::list< double > &list_t, const std::list< double > &list_x)
 Creates a scalar trajectory \(x(\cdot)\) from a list of values.
 
 Trajectory (const Trajectory &traj)
 Creates a copy of a scalar trajectory \(x(\cdot)\).
 
 ~Trajectory ()
 Trajectory destructor.
 
const Trajectoryoperator= (const Trajectory &x)
 Returns a copy of a Trajectory.
 
int size () const
 Returns the dimension of the scalar trajectory (always 1)
 
const Interval tdomain () const
 Returns the temporal definition domain of this trajectory.
 
TrajDefnType definition_type () const
 Returns the definition type of this trajectory.
 
Accessing values
const std::map< double, double > & sampled_map () const
 Returns the map of values, if the object is defined as a map.
 
const TFunction * tfunction () const
 Returns the temporal function, if the object is an analytic trajectory.
 
const Interval codomain () const
 Returns the interval of feasible values.
 
double operator() (double t) const
 Returns the evaluation of this trajectory at \(t\).
 
const Interval operator() (const Interval &t) const
 Returns the interval evaluation of this trajectory over \([t]\).
 
double first_value () const
 Returns the value \(x(t_0)\).
 
double last_value () const
 Returns the value \(x(t_f)\).
 
Tests
bool not_defined () const
 Tests whether this trajectory is defined or not.
 
bool operator== (const Trajectory &x) const
 Returns true if this trajectory is equal to \(x(\cdot)\).
 
bool operator!= (const Trajectory &x) const
 Returns true if this trajectory is different from \(x(\cdot)\).
 
Setting values
void set (double y, double t)
 Sets a value \(y\) at \(t\): \(x(t)=y\).
 
Trajectorytruncate_tdomain (const Interval &tdomain)
 Truncates the tdomain of \(x(\cdot)\).
 
Trajectoryshift_tdomain (double a)
 Shifts the tdomain \([t_0,t_f]\) of \(x(\cdot)\).
 
bool constant_timestep (double &h) const
 Returns true if the same amount of time separates each value.
 
Trajectorysample (double timestep)
 Samples the trajectory by adding new points to the map of values.
 
Trajectorysample (const Trajectory &x)
 Samples this trajectory so that it will share the same sampling of \(x(\cdot)\).
 
Trajectorymake_continuous ()
 Makes a trajectory continuous by avoiding infinite slopes.
 
Integration
const Trajectory primitive (double c=0.) const
 Computes an approximative primitive of \(x(\cdot)\).
 
const Trajectory primitive (double c, double timestep) const
 Computes an approximative primitive of \(x(\cdot)\) with some time discretization \(\delta\).
 
const Trajectory diff () const
 Differentiates this trajectory.
 
double finite_diff (double t, double h) const
 Computes the finite difference at \(t\), with an automatic order of accuracy.
 
Assignments operators
const Trajectoryoperator+= (double x)
 Operates +=.
 
const Trajectoryoperator+= (const Trajectory &x)
 Operates +=.
 
const Trajectoryoperator-= (double x)
 Operates -=.
 
const Trajectoryoperator-= (const Trajectory &x)
 Operates -=.
 
const Trajectoryoperator*= (double x)
 Operates *=.
 
const Trajectoryoperator*= (const Trajectory &x)
 Operates *=.
 
const Trajectoryoperator/= (double x)
 Operates /=.
 
const Trajectoryoperator/= (const Trajectory &x)
 Operates /=.
 
- Public Member Functions inherited from codac::DynamicalItem
virtual ~DynamicalItem ()
 DynamicalItem destructor.
 

Protected Member Functions

const IntervalVector codomain_box () const
 Returns the box \(x([t_0,t_f])\).
 
void compute_codomain ()
 Computes the envelope of trajectory values.
 

Protected Attributes

Interval m_tdomain = Interval::EMPTY_SET
 temporal domain \([t_0,t_f]\) of the trajectory
 
Interval m_codomain = Interval::EMPTY_SET
 envelope of the values of the trajectory
 
TrajDefnType m_traj_def_type = TrajDefnType::MAP_OF_VALUES
 definition type
 
TFunction * m_function = nullptr
 optional pointer to the analytic expression of this trajectory
 
std::map< double, double > m_map_values
 optional map of values <t,y>: \(x(t)=y\)
 

String

const std::string class_name () const
 Returns the name of this class.
 

Additional Inherited Members

- Static Public Member Functions inherited from codac::DynamicalItem
static bool valid_tdomain (const Interval &tdomain)
 Verifies that this interval is a feasible tdomain.
 

Detailed Description

One dimensional trajectory \(x(\cdot)\), defined as a temporal map of values.

Note
Use TrajectoryVector for the multi-dimensional case

Constructor & Destructor Documentation

◆ Trajectory() [1/6]

codac::Trajectory::Trajectory ( )

Creates an empty scalar trajectory \(x(\cdot)\).

The trajectory is made of an empty map of values.

◆ Trajectory() [2/6]

codac::Trajectory::Trajectory ( const Interval & tdomain,
const TFunction & f )

Creates a scalar trajectory \(x(\cdot)\) from an analytic expression.

Parameters
tdomaintemporal domain \([t_0,t_f]\)
fTFunction object defining the trajectory: \(x(t)=f(t)\)

◆ Trajectory() [3/6]

codac::Trajectory::Trajectory ( const Interval & tdomain,
const TFunction & f,
double timestep )

Creates a scalar trajectory \(x(\cdot)\) from an analytic expression, and transforms it as a map of values (sampling procedure)

Parameters
tdomaintemporal domain \([t_0,t_f]\)
fTFunction object defining the trajectory: \(x(t)=f(t)\)
timestepsampling value \(\delta\) for the temporal discretization (double)

◆ Trajectory() [4/6]

codac::Trajectory::Trajectory ( const std::map< double, double > & m_map_values)
explicit

Creates a scalar trajectory \(x(\cdot)\) from a map of values.

Parameters
m_map_valuesmap<t,y> defining the trajectory: \(x(t)=y\)

◆ Trajectory() [5/6]

codac::Trajectory::Trajectory ( const std::list< double > & list_t,
const std::list< double > & list_x )
explicit

Creates a scalar trajectory \(x(\cdot)\) from a list of values.

Values and datations are separated into two lists.

Parameters
list_tlist of time keys
list_xlist of values

◆ Trajectory() [6/6]

codac::Trajectory::Trajectory ( const Trajectory & traj)

Creates a copy of a scalar trajectory \(x(\cdot)\).

Parameters
trajTrajectory to be duplicated

Member Function Documentation

◆ operator=()

const Trajectory & codac::Trajectory::operator= ( const Trajectory & x)

Returns a copy of a Trajectory.

Parameters
xthe Trajectory object to be copied
Returns
a new Trajectory object with same values/definition

◆ size()

int codac::Trajectory::size ( ) const
virtual

Returns the dimension of the scalar trajectory (always 1)

Returns
1

Implements codac::DynamicalItem.

◆ tdomain()

const Interval codac::Trajectory::tdomain ( ) const
virtual

Returns the temporal definition domain of this trajectory.

Returns
an Interval object \([t_0,t_f]\)

Implements codac::DynamicalItem.

◆ definition_type()

TrajDefnType codac::Trajectory::definition_type ( ) const

Returns the definition type of this trajectory.

Returns
TrajDefnType::ANALYTIC_FNC or TrajDefnType::MAP_OF_VALUES

◆ sampled_map()

const std::map< double, double > & codac::Trajectory::sampled_map ( ) const

Returns the map of values, if the object is defined as a map.

Returns
a map<t,y> of values, or an empty map

◆ tfunction()

const TFunction * codac::Trajectory::tfunction ( ) const

Returns the temporal function, if the object is an analytic trajectory.

Returns
a pointer to a TFunction object

◆ codomain()

const Interval codac::Trajectory::codomain ( ) const

Returns the interval of feasible values.

Returns
an Interval object \(x([t_0,t_f])\)

◆ operator()() [1/2]

double codac::Trajectory::operator() ( double t) const

Returns the evaluation of this trajectory at \(t\).

Note
Be careful, if the trajectory is defined from an analytic function, then an approximation will be made (since the TFunction returns a boxed evaluation, while the expected returned value is a real here). Please use the operator(Interval(double)) for a reliable evaluation.
Parameters
tthe temporal key (double, must belong to the trajectory's tdomain)
Returns
real value \(x(t)\)

◆ operator()() [2/2]

const Interval codac::Trajectory::operator() ( const Interval & t) const

Returns the interval evaluation of this trajectory over \([t]\).

Parameters
tthe subtdomain (Interval, must be a subset of the trajectory's domain)
Returns
Interval envelope \(x([t])\)

◆ first_value()

double codac::Trajectory::first_value ( ) const

Returns the value \(x(t_0)\).

Returns
real value \(x(t_0)\)

◆ last_value()

double codac::Trajectory::last_value ( ) const

Returns the value \(x(t_f)\).

Returns
real value \(x(t_f)\)

◆ not_defined()

bool codac::Trajectory::not_defined ( ) const

Tests whether this trajectory is defined or not.

Returns
false in case of non-empty map, or missing definition from a TFunction object, true otherwise

◆ operator==()

bool codac::Trajectory::operator== ( const Trajectory & x) const

Returns true if this trajectory is equal to \(x(\cdot)\).

Parameters
xthe Trajectory object
Returns
true in case of equality

◆ operator!=()

bool codac::Trajectory::operator!= ( const Trajectory & x) const

Returns true if this trajectory is different from \(x(\cdot)\).

Parameters
xthe Trajectory object
Returns
true in case of difference

◆ set()

void codac::Trajectory::set ( double y,
double t )

Sets a value \(y\) at \(t\): \(x(t)=y\).

Note
The trajectory must not be defined from an analytic function
Parameters
ylocal value of the trajectory
tthe temporal key (double, must belong to the trajectory's tdomain)

◆ truncate_tdomain()

Trajectory & codac::Trajectory::truncate_tdomain ( const Interval & tdomain)

Truncates the tdomain of \(x(\cdot)\).

Note
The new tdomain must be a subset of the old one
Parameters
tdomainnew temporal domain \([t_0,t_f]\)
Returns
a reference to this trajectory

◆ shift_tdomain()

Trajectory & codac::Trajectory::shift_tdomain ( double a)

Shifts the tdomain \([t_0,t_f]\) of \(x(\cdot)\).

Note
If the trajectory is defined from a map of values, the key of each value will be shifted. In case of a definition from an analytic function, only the tdomain will be changed.
Parameters
athe offset value so that \([t_0,t_f]:=[t_0-a,t_f-a]\)
Returns
a reference to this trajectory

◆ constant_timestep()

bool codac::Trajectory::constant_timestep ( double & h) const

Returns true if the same amount of time separates each value.

Parameters
hthe evaluated timestep (constant if true is returned)
Returns
true if h is constant

◆ sample() [1/2]

Trajectory & codac::Trajectory::sample ( double timestep)

Samples the trajectory by adding new points to the map of values.

Note
If the trajectory is defined as an analytic function, then the object is transformed into a map of values and the TFunction object is deleted.
Parameters
timestepsampling value \(\delta\) for the temporal discretization (double)
Returns
a reference to this trajectory

◆ sample() [2/2]

Trajectory & codac::Trajectory::sample ( const Trajectory & x)

Samples this trajectory so that it will share the same sampling of \(x(\cdot)\).

Note
If the trajectory is defined as an analytic function, then the object is transformed into a map of values and the TFunction object is deleted.
The previous sampling of this trajectory is preserved
Parameters
xthe Trajectory from which the new sampling will come from
Returns
a reference to this trajectory

◆ make_continuous()

Trajectory & codac::Trajectory::make_continuous ( )

Makes a trajectory continuous by avoiding infinite slopes.

Note
This is mainly used when angles are expressed between \([-\pi,\pi]\), which produces troublesome discontinuities. For instance, a tube directly built from such discontinuous trajectory will be made of very large slices, inducing unwanted pessimism.
The previous sampling of this trajectory is preserved
Returns
a reference to this trajectory

◆ primitive() [1/2]

const Trajectory codac::Trajectory::primitive ( double c = 0.) const

Computes an approximative primitive of \(x(\cdot)\).

Note
The trajectory must not be defined from an analytic function. Please use the other method with time discretization for such case.
Parameters
cthe constant of integration (0. by default)
Returns
a new Trajectory object with the same temporal keys

◆ primitive() [2/2]

const Trajectory codac::Trajectory::primitive ( double c,
double timestep ) const

Computes an approximative primitive of \(x(\cdot)\) with some time discretization \(\delta\).

Parameters
cthe constant of integration
timestepsampling value \(\delta\) for the temporal discretization (double)
Returns
a new Trajectory object with the specified time discretization

◆ diff()

const Trajectory codac::Trajectory::diff ( ) const

Differentiates this trajectory.

Note
If the trajectory is defined from an analytic function, the exact differentiation is returned. Otherwise, from a map of values, finite differences are computed. In this case, the timestep of the values must be constant for accurate computation.
Returns
a derivative trajectory

◆ finite_diff()

double codac::Trajectory::finite_diff ( double t,
double h ) const

Computes the finite difference at \(t\), with an automatic order of accuracy.

Central, forward or backward finite differences are computed.

Note
This function only works with trajectories defined as a map of values.
A uniform grid spacing is assumed.
Parameters
tthe temporal key (double, must belong to the trajectory's tdomain)
htemporal timestep around t
Returns
a derivative trajectory

◆ operator+=() [1/2]

const Trajectory & codac::Trajectory::operator+= ( double x)

Operates +=.

Parameters
xdouble
Returns
(*this)+=x

◆ operator+=() [2/2]

const Trajectory & codac::Trajectory::operator+= ( const Trajectory & x)

Operates +=.

Parameters
xTrajectory
Returns
(*this)+=x

◆ operator-=() [1/2]

const Trajectory & codac::Trajectory::operator-= ( double x)

Operates -=.

Parameters
xdouble
Returns
(*this)-=x

◆ operator-=() [2/2]

const Trajectory & codac::Trajectory::operator-= ( const Trajectory & x)

Operates -=.

Parameters
xTrajectory
Returns
(*this)-=x

◆ operator*=() [1/2]

const Trajectory & codac::Trajectory::operator*= ( double x)

Operates *=.

Parameters
xdouble
Returns
(this)=x

◆ operator*=() [2/2]

const Trajectory & codac::Trajectory::operator*= ( const Trajectory & x)

Operates *=.

Parameters
xTrajectory
Returns
(this)=x

◆ operator/=() [1/2]

const Trajectory & codac::Trajectory::operator/= ( double x)

Operates /=.

Parameters
xdouble
Returns
(*this)/=x

◆ operator/=() [2/2]

const Trajectory & codac::Trajectory::operator/= ( const Trajectory & x)

Operates /=.

Parameters
xTrajectory
Returns
(*this)/=x

◆ class_name()

const std::string codac::Trajectory::class_name ( ) const
inlinevirtual

Returns the name of this class.

Note
Only used for some generic display method
Returns
the predefined name

Implements codac::DynamicalItem.

425{ return "Trajectory"; };

◆ codomain_box()

const IntervalVector codac::Trajectory::codomain_box ( ) const
protectedvirtual

Returns the box \(x([t_0,t_f])\).

Note
Used for genericity purposes
Returns
the envelope of codomain values

Implements codac::DynamicalItem.


The documentation for this class was generated from the following file: