# barrier

## Syntax

## Description

`barrier(`

adds a barrier along a piecewise, clothoid curve that smoothly connects the specified
barrier centers. This approach is useful when adding barriers to edges of roads that
intersect or overlap.`scenario`

,`barrierCenters`

)

`barrier(`

specifies the angle by which the barrier tilts when traversing the barrier centers.`scenario`

,`barrierCenters`

,`bankAngle`

)

`barrier(___,`

sets barrier properties using one or more name-value pair arguments, in addition to any
combination of input arguments from previous syntaxes.`Name,Value`

)

*Barriers* are composed of individual elements called barrier
segments. Use name-value pair arguments such as `'SegmentLength'`

,
`'SegmentGap'`

, `'Width'`

and
`'Height'`

to tune the properties of individual barrier segments.
Jersey barriers and guardrails are the two types of barriers that you can add to a scenario.
Specify the appropriate `'Mesh'`

and `'ClassID'`

arguments to represent the barrier as a guardrail or a jersey barrier.

## Examples

### Add Barriers Along Road Edges in Driving Scenario

Create a driving scenario and add a curved road.

scenario = drivingScenario; roadCenters = [-14.1 -4.3; 9 -10; 37 -8; 60 3.9; 81.2 29.4; 83.4 57.9]; road1 = road(scenario,roadCenters);

Add a barrier along the right edge of the road.

barrier(scenario,road1)

Add another barrier along the left edge of the road with a lateral offset of 1 m from the edge. Specify a gap of 1 m between individual barrier segments.

barrier(scenario,road1,'RoadEdge',"left",'SegmentGap',1,'RoadEdgeOffset',1)

Plot the scenario.

plot(scenario)

### Add Barriers to Driving Scenario at Specific Points

Create a driving scenario and add a straight road.

scenario2 = drivingScenario; roadCenters = [0 0; 20 0]; rr = road(scenario2,roadCenters);

Specify appropriate barrier centers and add a barrier on the road, covering the entire width of the road.

```
barrierCenters = [20 3; 20 0; 20 -3];
barrier(scenario2,barrierCenters,'SegmentGap',0.2)
```

Add two barriers on the road, each covering half the width of the road.

barrierCenters1 = [12 3; 12 0]; barrierCenters2 = [6 -3; 6 0]; barrier(scenario2,barrierCenters1,'SegmentGap',0.2) barrier(scenario2,barrierCenters2,'SegmentGap',0.2)

Plot the scenario.

plot(scenario2)

## Input Arguments

`scenario`

— Driving scenario

`drivingScenario`

object

Driving scenario, specified as a `drivingScenario`

object.

`rd`

— Road to add a barrier along

`road`

object

Road to add a barrier along, specified as a `road`

object.

`barrierCenters`

— Barrier center coordinates

real-valued *N*

-by-3 matrix | real-valued *N*

-by-2 matrix

*N*

*N*

Barrier center coordinates, specified as an *N*-by-3 or
*N*-by-2 matrix.

If

`barrierCenters`

is an*N*-by-3 matrix, then each matrix row represents the (*x*,*y*,*z*) coordinates of a barrier center.If

`barrierCenters`

is an*N*-by-2 matrix, then each matrix row represents the (*x*,*y*) coordinates of a barrier center. The*z*-coordinate of each barrier center is zero.

The function connects the coordinates along a smooth, piecewise, clothoid curve, and adds a barrier with the curve as its center line. Units are in meters.

`bankAngle`

— Banking angle of barrier

`0`

(default) | scalar | real-valued *N*

-by-1 vector

*N*

Banking angle of barrier, specified as a real-valued *N*-by-1 vector. *N* is the number of barrier
centers. The *bankAngle* is the roll angle of the
barrier along the direction of the curve formed by the barrier centers. Units are in
degrees.

### Name-Value Arguments

Specify optional pairs of arguments as
`Name1=Value1,...,NameN=ValueN`

, where `Name`

is
the argument name and `Value`

is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.

*
Before R2021a, use commas to separate each name and value, and enclose*
`Name`

*in quotes.*

**Example: **`'RoadEdge','left'`

adds a barrier along the left edge of the
road.

`RoadEdge`

— Edge of road along which to place a barrier

`'right'`

(default) | `'left'`

Edge of the road along which to place a barrier, specified as the comma-separated
pair consisting of `'RoadEdge'`

and `'right'`

or
`'left'`

. Use `'RoadEdge'`

only when you specify
a `road`

object to add a barrier along.

`RoadEdgeOffset`

— Lateral offset from road edge

scalar | real-valued *N*

-by-1 vector

*N*

Lateral offset from road edge, specified as the comma-separated pair consisting of
`'RoadEdgeOffset'`

and a scalar or real-valued
*N*-by-1 vector. *N* is the number of
barrier centers. A positive offset value moves the barrier away from the road and a
negative offset value moves the barrier into the road. Units are in meters.
`'RoadEdgeOffset'`

is valid only when you specify a `road`

object and `'RoadEdge'`

argument.

`SegmentLength`

— Length of each barrier segment

`5`

(default) | positive real scalar

Length of each barrier segment, specified as the comma-separated pair consisting
of `'SegmentLength'`

and a positive real scalar. Units are in meters.

`SegmentGap`

— Distance between consecutive barrier segments

`0`

(default) | positive real scalar

Distance between consecutive barrier segments, specified as the comma-separated
pair consisting of `'SegmentGap'`

and a positive real scalar. Units
are in meters.

`Width`

— Width of each barrier segment

`0.5`

(default) | positive real scalar

Width of each barrier segment, specified as the comma-separated pair consisting of
`'Width'`

and a positive real scalar. Units are in meters.

`Height`

— Height of each barrier segment

`0.75`

(default) | positive real scalar

Height of each barrier segment, specified as the comma-separated pair consisting
of `'Height'`

and a positive real scalar. Units are in meters.

`Mesh`

— Mesh representation of barrier

`extendedObjectMesh`

object

Mesh representation of the barrier, specified as the comma-separated pair
consisting of `'Mesh'`

and a valid
`extendedObjectMesh`

object. The available meshes for barrier are
`driving.scenario.jerseyBarrierMesh`

, representing a Jersey barrier and
`driving.scenario.guardrailMesh`

, representing a guardrail. The `lidarPointCloudGenerator`

system object uses this mesh to generate
detections.

`PlotColor`

— Display color of barrier

`[0.6 0.6 0.6]`

(default) | RGB triplet | hexadecimal color code | color name | short color name

Display color of barrier, specified as the comma-separated pair consisting of
`'PlotColor'`

and an RGB triplet, hexadecimal color code, color
name, or short color name.

The barrier appears in the specified color in all programmatic scenario
visualizations, including the `plot`

function, `chasePlot`

function, and plotting functions of `birdsEyePlot`

objects. If you import the scenario into the Driving Scenario
Designer app, then the barrier appears in this color in all app
visualizations. If you import the scenario into Simulink^{®}, then the barrier appears in this color in the Bird's-Eye
Scope.

For a custom color, specify an RGB triplet or a hexadecimal color code.

An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range

`[0,1]`

, for example,`[0.4 0.6 0.7]`

.A hexadecimal color code is a string scalar or character vector that starts with a hash symbol (

`#`

) followed by three or six hexadecimal digits, which can range from`0`

to`F`

. The values are not case sensitive. Therefore, the color codes`"#FF8800"`

,`"#ff8800"`

,`"#F80"`

, and`"#f80"`

are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.

Color Name | Short Name | RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|---|---|

`"red"` | `"r"` | `[1 0 0]` | `"#FF0000"` | |

`"green"` | `"g"` | `[0 1 0]` | `"#00FF00"` | |

`"blue"` | `"b"` | `[0 0 1]` | `"#0000FF"` | |

`"cyan"`
| `"c"` | `[0 1 1]` | `"#00FFFF"` | |

`"magenta"` | `"m"` | `[1 0 1]` | `"#FF00FF"` | |

`"yellow"` | `"y"` | `[1 1 0]` | `"#FFFF00"` | |

`"black"` | `"k"` | `[0 0 0]` | `"#000000"` | |

`"white"` | `"w"` | `[1 1 1]` | `"#FFFFFF"` |

Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB^{®} uses in many types of plots.

RGB Triplet | Hexadecimal Color Code | Appearance |
---|---|---|

`[0 0.4470 0.7410]` | `"#0072BD"` | |

`[0.8500 0.3250 0.0980]` | `"#D95319"` | |

`[0.9290 0.6940 0.1250]` | `"#EDB120"` | |

`[0.4940 0.1840 0.5560]` | `"#7E2F8E"` | |

`[0.4660 0.6740 0.1880]` | `"#77AC30"` | |

`[0.3010 0.7450 0.9330]` | `"#4DBEEE"` | |

`[0.6350 0.0780 0.1840]` | `"#A2142F"` |

`RCSPattern`

— Radar cross-section pattern of barrier

`[10 10; 10 10]`

(default) | *Q*-by-*P* real-valued matrix

Radar cross-section (RCS) pattern of the barrier, specified as the comma-separated
pair consisting of `'RCSPattern'`

and a
*Q*-by-*P* real-valued matrix. The RCS is a
function of the azimuth and elevation angles, where:

*Q*is the number of elevation angles specified by the`'RCSElevationAngles'`

name-value pair argument.*P*is the number of azimuth angles specified by the`'RCSAzimuthAngles'`

name-value pair argument.

Units are in decibels per square meter (dBsm).

**Example: **`5.8`

`RCSAzimuthAngles`

— Azimuth angles of RCS pattern of barrier

`[-180 180]`

(default) | *P*-element real-valued vector

Azimuth angles of RCS pattern of barrier, specified as the comma-separated pair
consisting of `'RCSAzimuthAngles'`

and a *P*-element
real-valued vector. *P* is the number of azimuth angles. Values are
in the range [–180°, 180°].

Each element of `'RCSAzimuthAngles'`

defines the azimuth angle
of the corresponding column of the `'RCSPattern'`

name-value pair
argument. Units are in degrees.

**Example: **`[-90:90]`

`RCSElevationAngles`

— Elevation angles of RCS pattern of barrier

`[-90 90]`

(default) | *Q*-element real-valued vector

Elevation angles of RCS pattern of barrier, specified as the comma-separated pair
consisting of `'RCSElevationAngles'`

and a
*Q*-element real-valued vector. *Q* is the number of
elevation angles. Values are in the range [–90°, 90°].

Each element of `'RCSElevationAngles'`

defines the elevation
angle of the corresponding row of the `'RCSPattern'`

name-value
pair argument. Units are in degrees.

**Example: **`[0:90]`

`ClassID`

— Classification identifier

`0`

(default) | `5`

| `6`

Classification identifier of the barrier, specified as the comma-separated pair
consisting of `'ClassID'`

and a nonnegative integer value of
`5`

or `6`

. The values `5`

and
`6`

correspond to Jersey barriers and guardrails, respectively.
Specify the appropriate Class ID for each barrier before importing the scenario into
the Driving Scenario
Designer app. For more information about the Class ID values for different
actors, refer to the description of the `'ClassID'`

name-value pair argument.

## Limitations

Road networks added using the

`roadNetwork`

function do not support barriers.

## Tips

For faster simulations, specify the input argument

`range`

for the`targetPoses`

function in the scenario advance loop.

## Version History

**Introduced in R2021a**

## See Also

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)