Skip to content
LIBRARY
Math.Tests.PolarToRectangular.md

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

BlockComponents.Math.Tests.PolarToRectangular()

Behavior

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
Flattened 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


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt