---
url: /dyad/stable/stdlib/BlockComponents/tests/Math.Tests.Atan2.md
description: >-
  Dyad Math.Tests.Atan2 docs.  Computes the four-quadrant arc tangent of
  constant and time-varying inputs.
---

# `Math.Tests.Atan2` {#Math.Tests.Atan2}

Computes the four-quadrant arc tangent of constant and time-varying inputs.

Connects constant sources with values 0 (u1) and 1 (u2) to an Atan2 block and verifies that atan2(0, 1) = 0. A second Atan2 block is driven by a sine wave on u1 (amplitude 2) with the x-component (u2) held at 1 so the angle sweeps negative and positive values while avoiding the atan2(0, 0) singularity.

## Usage {#Usage}

`BlockComponents.Math.Tests.Atan2()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( c1\_{+}y, atan2\_{block\_{+}u1} \right) \\
0 &= \mathrm{connect}\left( c2\_{+}y, atan2\_{block\_{+}u2} \right) \\
0 &= \mathrm{connect}\left( sine1\_{+}y, atan2\_{block_2\_{+}u1} \right) \\
0 &= \mathrm{connect}\left( c2\_{+}y, atan2\_{block_2\_{+}u2} \right) \\
\mathtt{c1.y}\left( t \right) &= \mathtt{c1.k} \\
\mathtt{c2.y}\left( t \right) &= \mathtt{c2.k} \\
\mathtt{atan2_block.y}\left( t \right) &= \arctan\left( \mathtt{atan2_block.u1}\left( t \right), \mathtt{atan2_block.u2}\left( t \right) \right) \\
\mathtt{sine1.y}\left( t \right) &= ifelse\left( \mathtt{sine1.continuous}, ifelse\left( t \geq \mathtt{sine1.start_time}, \sin\left( \mathtt{sine1.phase} + 6.2832 ~ \mathtt{sine1.frequency} ~ \left(  - \mathtt{sine1.shift_time} + t \right) \right), \sin\left( \mathtt{sine1.phase} + 6.2832 ~ \mathtt{sine1.frequency} ~ \left(  - \mathtt{sine1.shift_time} + \mathtt{sine1.start_time} \right) \right) \right) ~ \mathtt{sine1.amplitude}, ifelse\left( t \geq \mathtt{sine1.start_time}, \sin\left( \mathtt{sine1.phase} + 6.2832 ~ \mathtt{sine1.frequency} ~ \left(  - \mathtt{sine1.shift_time} + t \right) \right) ~ \mathtt{sine1.amplitude}, 0 \right) \right) + \mathtt{sine1.offset} \\
\mathtt{atan2_block_2.y}\left( t \right) &= \arctan\left( \mathtt{atan2_block_2.u1}\left( t \right), \mathtt{atan2_block_2.u2}\left( t \right) \right)
\end{align}
$$

## Source {#Source}

```dyad
"""
Computes the four-quadrant arc tangent of constant and time-varying inputs.

Connects constant sources with values 0 (u1) and 1 (u2) to an Atan2 block
and verifies that atan2(0, 1) = 0. A second Atan2 block is driven by a sine
wave on u1 (amplitude 2) with the x-component (u2) held at 1 so the angle
sweeps negative and positive values while avoiding the atan2(0, 0)
singularity.
"""
test component Atan2
  "Constant source providing the first input (y-component)"
  c1 = BlockComponents.Sources.Constant(k = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant source providing the second input (x-component)"
  c2 = BlockComponents.Sources.Constant(k = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "Atan2 block under test"
  atan2_block = BlockComponents.Math.Atan2() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 110, "x2": 260, "y2": 210, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source sweeping the y-component of the second block"
  sine1 = BlockComponents.Sources.Sine(amplitude = 2, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 260, "x2": 120, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
  "Second Atan2 block driven by the sine source"
  atan2_block_2 = BlockComponents.Math.Atan2() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 290, "x2": 260, "y2": 390, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c1.y, atan2_block.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 70}, {"x": 140, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(c2.y, atan2_block.u2) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sine1.y, atan2_block_2.u1) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(c2.y, atan2_block_2.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 140, "y": 370}], "E": 2}],
      "junctions": [{"x": 140, "y": 190}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["atan2_block.y", "atan2_block_2.y", "sine1.y"]}
      }
    }
  }
}
end
```

```dyad
"""
Computes the four-quadrant arc tangent of constant and time-varying inputs.

Connects constant sources with values 0 (u1) and 1 (u2) to an Atan2 block
and verifies that atan2(0, 1) = 0. A second Atan2 block is driven by a sine
wave on u1 (amplitude 2) with the x-component (u2) held at 1 so the angle
sweeps negative and positive values while avoiding the atan2(0, 0)
singularity.
"""
test component Atan2
  "Constant source providing the first input (y-component)"
  c1 = BlockComponents.Sources.Constant(k = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant source providing the second input (x-component)"
  c2 = BlockComponents.Sources.Constant(k = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "Atan2 block under test"
  atan2_block = BlockComponents.Math.Atan2() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 110, "x2": 260, "y2": 210, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source sweeping the y-component of the second block"
  sine1 = BlockComponents.Sources.Sine(amplitude = 2, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 260, "x2": 120, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
  "Second Atan2 block driven by the sine source"
  atan2_block_2 = BlockComponents.Math.Atan2() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 160, "y1": 290, "x2": 260, "y2": 390, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c1.y, atan2_block.u1) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 70}, {"x": 140, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(c2.y, atan2_block.u2) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sine1.y, atan2_block_2.u1) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(c2.y, atan2_block_2.u2) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 140, "y": 370}], "E": 2}],
      "junctions": [{"x": 140, "y": 190}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {"signals": ["atan2_block.y", "atan2_block_2.y", "sine1.y"]}
      }
    }
  }
}
end
```

## Test Cases {#Test-Cases}

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

```julia
plt
```

![](xlkaqop.svg)

```julia
plt
```

![](zoxxizg.svg)

```julia
plt
```

![](fxxkvdu.svg)

## Related {#Related}

* Examples

* Experiments

* Analyses

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

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

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

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