Main Content

interpolate

Interpolate between states

Description

interpStates = interpolate(space,state1,state2,ratio) interpolates states between the specified start state state1 and end state state2 based on the specified interpolation ratio ratio.

example

Examples

collapse all

Create an SE(2) state space with default properties.

space = stateSpaceSE2
space = 
  stateSpaceSE2 with properties:

                 Name: 'SE2'
          StateBounds: [3x2 double]
    NumStateVariables: 3
             WeightXY: 1
          WeightTheta: 0.1000

Create a pair of states in 2-D space.

state1 = [2 10 -pi];
state2 = [0 -2.5 -pi/4];

Interpolate halfway between two states.

state = interpolate(space,state1,state2,0.5)
state = 1×3

    1.0000    3.7500   -1.9635

Interpolate multiple points with a fixed interval.

states = interpolate(space,state1,state2,0:0.02:1)
states = 51×3

    2.0000   10.0000   -3.1416
    1.9600    9.7500   -3.0945
    1.9200    9.5000   -3.0473
    1.8800    9.2500   -3.0002
    1.8400    9.0000   -2.9531
    1.8000    8.7500   -2.9060
    1.7600    8.5000   -2.8588
    1.7200    8.2500   -2.8117
    1.6800    8.0000   -2.7646
    1.6400    7.7500   -2.7175
      ⋮

Create an SE(3) state space with default properties.

space = stateSpaceSE3
space = 
  stateSpaceSE3 with properties:

                 Name: 'SE3'
          StateBounds: [7x2 double]
    NumStateVariables: 7
            WeightXYZ: 1
     WeightQuaternion: 0.1000

Create a pair of states in 3-D space.

state1 = [2 10 3 0.2 0 0 0.8];
state2 = [0 -2.5 4 0.7 0.3 0 0];

Interpolate halfway between two states.

state = interpolate(space,state1,state2,0.5)
state = 1×7

    1.0000    3.7500    3.5000    0.7428    0.2519         0    0.6203

Interpolate multiple points with a fixed interval.

states = interpolate(space,state1,state2,0:0.02:1)
states = 51×7

    2.0000   10.0000    3.0000    0.2425         0         0    0.9701
    1.9600    9.7500    3.0200    0.2663    0.0109         0    0.9638
    1.9200    9.5000    3.0400    0.2899    0.0217         0    0.9568
    1.8800    9.2500    3.0600    0.3133    0.0326         0    0.9491
    1.8400    9.0000    3.0800    0.3365    0.0434         0    0.9407
    1.8000    8.7500    3.1000    0.3594    0.0542         0    0.9316
    1.7600    8.5000    3.1200    0.3821    0.0650         0    0.9218
    1.7200    8.2500    3.1400    0.4045    0.0757         0    0.9114
    1.6800    8.0000    3.1600    0.4266    0.0864         0    0.9003
    1.6400    7.7500    3.1800    0.4484    0.0969         0    0.8886
      ⋮

Input Arguments

collapse all

State space object, specified as a stateSpaceSE2, stateSpaceSE3, stateSpaceDubins, or stateSpaceReedsShepp object.

Start state for interpolation, specified as a three-element or seven-element vector of real values.

For the 2-D state space objects stateSpaceSE2, stateSpaceDubins, and stateSpaceReedsShepp, the state is a vector of form [x y theta], which defines the xy-position and orientation angle theta of a state in the state space.

For the 3-D state space object stateSpaceSE3, the state is a vector of form [x y z qw qx qy qz], which defines the xyz-position and quaternion orientation [qw qx qy qz] of a state in the state space.

Data Types: single | double

End state for interpolation, specified as a three-element or seven-element vector of real values.

For the 2-D state space objects stateSpaceSE2, stateSpaceDubins, and stateSpaceReedsShepp, the state is a vector of form [x y theta], which defines the xy-position and orientation angle theta of a state in the state space.

For the 3-D state space object stateSpaceSE3, the state is a vector of form [x y z qw qx qy qz], which defines the xyz-position and quaternion orientation [qw qx qy qz] of a state in the state space.

Data Types: single | double

Interpolation ratio, specified as a scalar in the range of [0, 1], or an n-element column vector of values in the range [0, 1]. n is the number of desired interpolation points.

Data Types: single | double

Output Arguments

collapse all

Interpolated states, returned as an n-by-3 or n-by-7 matrix of real values. n is the number of interpolation points specified by the ratio input argument.

For the 2-D state space objects stateSpaceSE2, stateSpaceDubins, and stateSpaceReedsShepp, each row is of form [x y theta], which defines the xy-position and orientation angle theta of the interpolated states.

For the 3-D state space object stateSpaceSE3, each row is of form [x y z qw qx qy qz], which defines the xyz-position and quaternion orientation [qw qx qy qz] of the interpolated states.

Data Types: single | double

Version History

Introduced in R2019b