---
url: /dyad/dev/stdlib/BlockComponents/tests/Math.Tests.PolarToRectangular.md
description: >-
  Dyad Math.Tests.PolarToRectangular docs.  Converts constant and time-varying
  polar coordinates to rectangular.
---

# `Math.Tests.PolarToRectangular` {#Math.Tests.PolarToRectangular}

Converts constant and time-varying polar coordinates to rectangular.

Connects constant sources with u_abs=5 and u_arg=0 to a PolarToRectangular block and verifies that y_re = 5_cos(0) = 5 and y_im = 5_sin(0) = 0. A second PolarToRectangular block holds the magnitude at 5 while a sine wave sweeps the angle, tracing a circle so y_re and y_im vary over their full ranges.

## Usage {#Usage}

`BlockComponents.Math.Tests.PolarToRectangular()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( c\_{abs\_{+}y}, p2r\_{+}u\_{abs} \right) \\
0 &= \mathrm{connect}\left( c\_{arg\_{+}y}, p2r\_{+}u\_{arg} \right) \\
0 &= \mathrm{connect}\left( c\_{abs\_{+}y}, p2r\_{2\_{+}u_abs} \right) \\
0 &= \mathrm{connect}\left( arg\_{sine\_{+}y}, p2r\_{2\_{+}u_arg} \right) \\
\mathtt{c_abs.y}\left( t \right) &= \mathtt{c_abs.k} \\
\mathtt{c_arg.y}\left( t \right) &= \mathtt{c_arg.k} \\
\mathtt{p2r.y_re}\left( t \right) &= \cos\left( \mathtt{p2r.u_arg}\left( t \right) \right) ~ \mathtt{p2r.u_abs}\left( t \right) \\
\mathtt{p2r.y_im}\left( t \right) &= \mathtt{p2r.u_abs}\left( t \right) ~ \sin\left( \mathtt{p2r.u_arg}\left( t \right) \right) \\
\mathtt{arg_sine.y}\left( t \right) &= \mathtt{arg_sine.offset} + ifelse\left( \mathtt{arg_sine.continuous}, \mathtt{arg_sine.amplitude} ~ ifelse\left( t \geq \mathtt{arg_sine.start_time}, \sin\left( \mathtt{arg_sine.phase} + 6.2832 ~ \mathtt{arg_sine.frequency} ~ \left(  - \mathtt{arg_sine.shift_time} + t \right) \right), \sin\left( \mathtt{arg_sine.phase} + 6.2832 ~ \mathtt{arg_sine.frequency} ~ \left(  - \mathtt{arg_sine.shift_time} + \mathtt{arg_sine.start_time} \right) \right) \right), ifelse\left( t \geq \mathtt{arg_sine.start_time}, \mathtt{arg_sine.amplitude} ~ \sin\left( \mathtt{arg_sine.phase} + 6.2832 ~ \mathtt{arg_sine.frequency} ~ \left(  - \mathtt{arg_sine.shift_time} + t \right) \right), 0 \right) \right) \\
\mathtt{p2r_2.y_re}\left( t \right) &= \cos\left( \mathtt{p2r_2.u_arg}\left( t \right) \right) ~ \mathtt{p2r_2.u_abs}\left( t \right) \\
\mathtt{p2r_2.y_im}\left( t \right) &= \mathtt{p2r_2.u_abs}\left( t \right) ~ \sin\left( \mathtt{p2r_2.u_arg}\left( t \right) \right)
\end{align}
$$

## Source {#Source}

```dyad
"""
Converts constant and time-varying polar coordinates to rectangular.

Connects constant sources with u_abs=5 and u_arg=0 to a PolarToRectangular
block and verifies that y_re = 5*cos(0) = 5 and y_im = 5*sin(0) = 0. A second
PolarToRectangular block holds the magnitude at 5 while a sine wave sweeps the
angle, tracing a circle so y_re and y_im vary over their full ranges.
"""
test component PolarToRectangular
  "Constant source providing the absolute value"
  c_abs = BlockComponents.Sources.Constant(k = 5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": -10, "x2": 120, "y2": 90, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant source providing the angle (0 radians)"
  c_arg = BlockComponents.Sources.Constant(k = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "PolarToRectangular block under test"
  p2r = BlockComponents.Math.PolarToRectangular() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 54, "x2": 270, "y2": 154, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source sweeping the angle of the second block"
  arg_sine = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 260, "x2": 120, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
  "Second PolarToRectangular block with a swept angle"
  p2r_2 = BlockComponents.Math.PolarToRectangular() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 232, "x2": 270, "y2": 332, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c_abs.y, p2r.u_abs) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 40}, {"x": 140, "y": 70}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(c_arg.y, p2r.u_arg) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 150, "y": 190}, {"x": 150, "y": 132}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(c_abs.y, p2r_2.u_abs) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 140, "y": 40}], "E": -1},
        {"S": -1, "M": [{"x": 140, "y": 248}], "E": 2}
      ],
      "junctions": [{"x": 140, "y": 70}],
      "renderStyle": "standard"
    }
  }
  connect(arg_sine.y, p2r_2.u_arg) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["p2r.y_re", "p2r.y_im", "p2r_2.y_re", "p2r_2.y_im", "arg_sine.y"]}
      }
    }
  }
}
end
```

```dyad
"""
Converts constant and time-varying polar coordinates to rectangular.

Connects constant sources with u_abs=5 and u_arg=0 to a PolarToRectangular
block and verifies that y_re = 5*cos(0) = 5 and y_im = 5*sin(0) = 0. A second
PolarToRectangular block holds the magnitude at 5 while a sine wave sweeps the
angle, tracing a circle so y_re and y_im vary over their full ranges.
"""
test component PolarToRectangular
  "Constant source providing the absolute value"
  c_abs = BlockComponents.Sources.Constant(k = 5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": -10, "x2": 120, "y2": 90, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant source providing the angle (0 radians)"
  c_arg = BlockComponents.Sources.Constant(k = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "PolarToRectangular block under test"
  p2r = BlockComponents.Math.PolarToRectangular() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 54, "x2": 270, "y2": 154, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source sweeping the angle of the second block"
  arg_sine = BlockComponents.Sources.Sine(amplitude = 3, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 260, "x2": 120, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
  "Second PolarToRectangular block with a swept angle"
  p2r_2 = BlockComponents.Math.PolarToRectangular() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 232, "x2": 270, "y2": 332, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c_abs.y, p2r.u_abs) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 40}, {"x": 140, "y": 70}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(c_arg.y, p2r.u_arg) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 150, "y": 190}, {"x": 150, "y": 132}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(c_abs.y, p2r_2.u_abs) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 140, "y": 40}], "E": -1},
        {"S": -1, "M": [{"x": 140, "y": 248}], "E": 2}
      ],
      "junctions": [{"x": 140, "y": 70}],
      "renderStyle": "standard"
    }
  }
  connect(arg_sine.y, p2r_2.u_arg) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["p2r.y_re", "p2r.y_im", "p2r_2.y_re", "p2r_2.y_im", "arg_sine.y"]}
      }
    }
  }
}
end
```

## Test Cases {#Test-Cases}

### Test Case `case1` {#Test-Case-case1}

```julia
plt
```

![](kmaildk.svg)

```julia
plt
```

![](gfjwfzt.svg)

```julia
plt
```

![](jgkalsc.svg)

```julia
plt
```

![](gfzjjwn.svg)

```julia
plt
```

![](dtjthiw.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`Constant`](Math.Tests.PolarToRectangular.md)

  * [`PolarToRectangular`](Math.Tests.PolarToRectangular.md)

  * [`PolarToRectangular`](Math.Tests.PolarToRectangular.md)

  * [`Sine`](Math.Tests.PolarToRectangular.md)
