Skip to content
LIBRARY
Math.Tests.RectangularToPolar.md

Math.Tests.RectangularToPolar

Converts constant and time-varying rectangular coordinates to polar.

Connects constant sources with u_re=3 and u_im=4 to a RectangularToPolar block and verifies that y_abs = sqrt(9+16) = 5 and y_arg = atan2(4,3) ≈ 0.9273. A second RectangularToPolar block holds the real part at 3 while a sine wave sweeps the imaginary part, so the magnitude and angle vary over time.

Usage

BlockComponents.Math.Tests.RectangularToPolar()

Behavior

Source

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

Connects constant sources with u_re=3 and u_im=4 to a RectangularToPolar
block and verifies that y_abs = sqrt(9+16) = 5 and
y_arg = atan2(4,3) ≈ 0.9273. A second RectangularToPolar block holds the real
part at 3 while a sine wave sweeps the imaginary part, so the magnitude and
angle vary over time.
"""
test component RectangularToPolar
  "Constant source providing the real part"
  c_re = BlockComponents.Sources.Constant(k = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant source providing the imaginary part"
  c_im = BlockComponents.Sources.Constant(k = 4) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "RectangularToPolar block under test"
  r2p = BlockComponents.Math.RectangularToPolar() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 50, "x2": 280, "y2": 150, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source sweeping the imaginary part of the second block"
  im_sine = BlockComponents.Sources.Sine(amplitude = 4, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 260, "x2": 120, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
  "Second RectangularToPolar block with a swept imaginary part"
  r2p_2 = BlockComponents.Math.RectangularToPolar() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 236, "x2": 270, "y2": 336, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c_re.y, r2p.u_re) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 145, "y": 70}, {"x": 145, "y": 71}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(c_im.y, r2p.u_im) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 190}, {"x": 140, "y": 124}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(c_re.y, r2p_2.u_re) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 150, "y": 257}], "E": 2}],
      "junctions": [{"x": 150, "y": 70}],
      "renderStyle": "standard"
    }
  }
  connect(im_sine.y, r2p_2.u_im) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {
          "signals": ["r2p.y_abs", "r2p.y_arg", "r2p_2.y_abs", "r2p_2.y_arg", "im_sine.y"]
        }
      }
    }
  }
}
end
Flattened Source
dyad
"""
Converts constant and time-varying rectangular coordinates to polar.

Connects constant sources with u_re=3 and u_im=4 to a RectangularToPolar
block and verifies that y_abs = sqrt(9+16) = 5 and
y_arg = atan2(4,3) ≈ 0.9273. A second RectangularToPolar block holds the real
part at 3 while a sine wave sweeps the imaginary part, so the magnitude and
angle vary over time.
"""
test component RectangularToPolar
  "Constant source providing the real part"
  c_re = BlockComponents.Sources.Constant(k = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant source providing the imaginary part"
  c_im = BlockComponents.Sources.Constant(k = 4) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
      },
      "tags": []
    }
  }
  "RectangularToPolar block under test"
  r2p = BlockComponents.Math.RectangularToPolar() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 50, "x2": 280, "y2": 150, "rot": 0}
      },
      "tags": []
    }
  }
  "Sine source sweeping the imaginary part of the second block"
  im_sine = BlockComponents.Sources.Sine(amplitude = 4, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 260, "x2": 120, "y2": 360, "rot": 0}
      },
      "tags": []
    }
  }
  "Second RectangularToPolar block with a swept imaginary part"
  r2p_2 = BlockComponents.Math.RectangularToPolar() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 236, "x2": 270, "y2": 336, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(c_re.y, r2p.u_re) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 145, "y": 70}, {"x": 145, "y": 71}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(c_im.y, r2p.u_im) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 190}, {"x": 140, "y": 124}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(c_re.y, r2p_2.u_re) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 150, "y": 257}], "E": 2}],
      "junctions": [{"x": 150, "y": 70}],
      "renderStyle": "standard"
    }
  }
  connect(im_sine.y, r2p_2.u_im) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1,
        "expect": {
          "signals": ["r2p.y_abs", "r2p.y_arg", "r2p_2.y_abs", "r2p_2.y_arg", "im_sine.y"]
        }
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt