# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

# rangeangle

Range and angle calculation

## Syntax

``````[rng,ang] = rangeangle(pos)``````
``````[rng,ang] = rangeangle(pos,refpos)``````
``````[rng,ang] = rangeangle(pos,refpos,refaxes)``````
``````[rng,ang] = rangeangle(___,model)``````

## Description

The function `rangeangle` determines the propagation path length and path direction of a signal from any point to a reference point. The function supports two propagation models — the free space model and the two-ray model. The free space model is a single line-of-sight path from a point to a reference point. The two-ray multipath model generates two paths. The first path follows the free-space path. The second path is a reflected path off a boundary plane at z = 0. Path directions are defined with respect to either the global coordinate system at the reference point or a local coordinate system at the reference point. Distances and angles at the reference point do not depend upon which direction the signal is travelling along the path. Path lengths are independent of the coordinate system.

example

``````[rng,ang] = rangeangle(pos)``` returns the propagation path length, `rng`, and direction, `ang`, of a signal path from one point or set of points, `pos`, to the reference point. In this syntax, the reference point coincides with the global coordinate system origin. Directions are specified by azimuth and elevation angles with respect to the global coordinate system. Signals follow a line-of-sight path from the source to the origin. The line-of-sight path corresponds to the geometric straight line between the points.```

example

``````[rng,ang] = rangeangle(pos,refpos)```, in addition, specifies a reference point, `refpos`. Directions are specified by azimuth and elevation with respect to a global coordinate system at the reference point.```

example

``````[rng,ang] = rangeangle(pos,refpos,refaxes)``` in addition, specifies the reference axes, `refaxes`. Path angles are defined by azimuth and elevation with respect to a local coordinate system with its origin at `refpos` and axes defined by `refaxes`.```

example

``````[rng,ang] = rangeangle(___,model)```, in addition, specifies a propagation model. When `model` is set to `'freespace'`, the signal propagates along a line-of-sight path from source point to reception point. When `model` is set to `'two-ray'`, the signal propagates along two paths from source point to reception point. The first path is the line-of-sight path. The second path is the reflecting path. In this case, the function returns the distances and angles for two paths for each source point.```

## Input Arguments

 `pos` Point position, specified as a 3-by-N real-valued matrix of rectangular coordinates where each column takes the form `[x;y;z]`. Each column in `pos` represents the coordinates of one position. Position units are meters. `refpos` Reference position, specified as a real-valued 3-by-1 vector of rectangular coordinates in the form `[x;y;z]`. The reference position is the origin of the local coordinate system. Ranges and angles to the columns of `pos` are measured with respect to `refpos`. Position units are meters. Default: `[0;0;0]` `refaxes` Local coordinate system axes, specified as a real-valued 3-by-3 matrix whose columns define the axes of the local coordinate system with origin at `refpos`. Each column in `refaxes` specifies the direction of an axis for the local coordinate system in rectangular coordinates `[x;y;z]`. Default: `[1 0 0;0 1 0;0 0 1]` `model` Propagation model, taking the value `'freespace'` or `'two-ray'`. Choosing `'freespace'` invokes the free space propagation model. Choosing `'two-ray'` invokes the two-ray propagation model. Default: `'freespace'`

## Output Arguments

 `rng` Propagation distance, returned as a 1-by-M vector of ranges from the source to the positions defined by the corresponding columns in `pos`. When `model` is set to `'freespace'`, M = N. When `model` is set to `'two-ray'`, M = 2N. Alternate columns of `ang` refer to the line-of-sight path and reflected path, respectively. Position units are meters. `ang` Azimuth and elevation angles, returned as a 2-by-M matrix whose columns are angles in the form `[azimuth;elevation]`. Each column corresponds to the positions specified in `pos`. When `model` is set to `'freespace'`, M = N. When `model` is set to `'two-ray'`, M = 2N. Alternate columns of `ang` refer to the line-of-sight path and reflected path, respectively. Angle units are in degrees.

## Examples

collapse all

Compute the range and angle of a target located at (1000,2000,50) meters from the origin.

```TargetLoc = [1000;2000;50]; [tgtrng,tgtang] = rangeangle(TargetLoc)```
```tgtrng = 2.2366e+03 ```
```tgtang = 63.4349 1.2810 ```

Compute the range and angle of a target located at (1000,2000,50) meters with respect to a local origin at (100,100,10) meters.

```TargetLoc = [1000;2000;50]; Origin = [100;100;10]; [tgtrng,tgtang] = rangeangle(TargetLoc,Origin)```
```tgtrng = 2.1028e+03 ```
```tgtang = 64.6538 1.0900 ```

Compute the range and angle of a target located at (1000,2000,50) meters but with respect to a local coordinate system origin at (100,100,10) meters. Choose a local coordinate reference frame that is rotated about the z-axis by 45° from the global coordinate axes.

```targetpos = [1000;2000;50]; origin = [100;100;10]; refaxes = [1/sqrt(2) -1/sqrt(2) 0; 1/sqrt(2) 1/sqrt(2) 0; 0 0 1]; [tgtrng,tgtang] = rangeangle(targetpos,origin,refaxes)```
```tgtrng = 2.1028e+03 ```
```tgtang = 19.6538 1.0900 ```

Compute the two-ray propagation distances and arrival angles of rays from a source located at (1000,1000,500) meters from the origin. The receiver is located at (100,100,200) meters from the origin.

```sourceLoc = [1000;1000;500]; receiverLoc = [100;100;200]; [sourcerngs,sourceangs] = rangeangle(sourceLoc,receiverLoc,'two-ray') ```
```sourcerngs = 1.0e+03 * 1.3077 1.4526 sourceangs = 45.0000 45.0000 13.2627 -28.8096 ```

Find the range and angle of the same target with the same origin but with respect to a local coordinate axes. The local coordinate axes are rotated around the z-axis by 45 degrees from the global coordinate axes.

```refaxes = rotz(45); [sourcerngs,sourceangs] = rangeangle(sourceLoc,receiverLoc,refaxes,'two-ray') ```
```sourcerngs = 1.0e+03 * 1.3077 1.4526 sourceangs = 0 0 13.2627 -28.8096 ```

collapse all

### Angles in Local and Global Coordinate Systems

The `rangeangle` function returns the path distance and path angles in either the global or local coordinate systems. Every antenna or microphone element and array has a gain pattern that is expressed in local angular coordinates of azimuth and elevation. As the element or array moves or rotates, the gain pattern is carried with it. To determine the strength of a signal’s transmission or reception, you must know the angle that the signal path makes with respect to the local angular coordinates of the element or array. By default, the `rangeangle` function determines the angle a signal path makes with respect to global coordinates. If you add the `refaxes` argument, you can compute the angles with respect to local coordinates. As an illustration, the figure below shows a 5-by-5 uniform rectangular array (URA) rotated from the global coordinates (xyz) using `refaxes`. The x' axis of the local coordinate system (x'y'z') is aligned with the main axis of the array and moves as the array moves. The path length is independent of orientation. The global coordinate system defines the azimuth and elevations angles (φ,θ) and the local coordinate system defines the azimuth and elevations angles (φ',θ').

Local and Global Coordinate Axes

### Free Space Propagation Model

The free-space signal propagation model states that a signal propagating from one point to another in a homogeneous, isotropic medium travels in a straight line, called the line-of-sight or direct path. The straight line is defined by the geometric vector from the radiation source to the destination. Similar assumptions are made for sonar but the term isovelocity channel is usually used in place of free space.

### Two-ray Propagation Model

A two-ray propagation channel is the next step up in complexity from a free-space channel and is the simplest case of a multipath propagation environment. The free-space channel models a straight-line line-of-sight path from point 1 to point 2. In a two-ray channel, the medium is specified as a homogeneous, isotropic medium with a reflecting planar boundary. The boundary is always set at z = 0. There are at most two rays propagating from point 1 to point 2. The first ray path propagates along the same line-of-sight path as in the free-space channel (see the `phased.FreeSpace` System object™). The line-of-sight path is often called the direct path. The second ray reflects off the boundary before propagating to point 2. According to the Law of Reflection , the angle of reflection equals the angle of incidence. In short-range simulations such as cellular communications systems and automotive radars, you can assume that the reflecting surface, the ground or ocean surface, is flat.

The `phased.TwoRayChannel` and `phased.WidebandTwoRayChannel` System objects model propagation time delay, phase shift, Doppler shift, and loss effects for both paths. For the reflected path, loss effects include reflection loss at the boundary.

The figure illustrates two propagation paths. From the source position, ss, and the receiver position, sr, you can compute the arrival angles of both paths, θ′los and θ′rp. The arrival angles are the elevation and azimuth angles of the arriving radiation with respect to a local coordinate system. In this case, the local coordinate system coincides with the global coordinate system. You can also compute the transmitting angles, θlos and θrp. In the global coordinates, the angle of reflection at the boundary is the same as the angles θrp and θ′rp. The reflection angle is important to know when you use angle-dependent reflection-loss data. You can determine the reflection angle by using the `rangeangle` function and setting the reference axes to the global coordinate system. The total path length for the line-of-sight path is shown in the figure by Rlos which is equal to the geometric distance between source and receiver. The total path length for the reflected path is Rrp= R1 + R2. The quantity L is the ground range between source and receiver.

You can easily derive exact formulas for path lengths and angles in terms of the ground range and objects heights in the global coordinate system.

`$\begin{array}{l}\stackrel{\to }{R}={\stackrel{\to }{x}}_{s}-{\stackrel{\to }{x}}_{r}\\ {R}_{los}=|\stackrel{\to }{R}|=\sqrt{{\left({z}_{r}-{z}_{s}\right)}^{2}+{L}^{2}}\\ {R}_{1}=\frac{{z}_{r}}{{z}_{r}+{z}_{z}}\sqrt{{\left({z}_{r}+{z}_{s}\right)}^{2}+{L}^{2}}\\ {R}_{2}=\frac{{z}_{s}}{{z}_{s}+{z}_{r}}\sqrt{{\left({z}_{r}+{z}_{s}\right)}^{2}+{L}^{2}}\\ {R}_{rp}={R}_{1}+{R}_{2}=\sqrt{{\left({z}_{r}+{z}_{s}\right)}^{2}+{L}^{2}}\\ \mathrm{tan}{\theta }_{los}=\frac{\left({z}_{s}-{z}_{r}\right)}{L}\\ \mathrm{tan}{\theta }_{rp}=-\frac{\left({z}_{s}+{z}_{r}\right)}{L}\\ {{\theta }^{\prime }}_{los}=-{\theta }_{los}\\ {{\theta }^{\prime }}_{rp}={\theta }_{rp}\end{array}$`