|
| 1 | +# https://www.electrical4u.com/delta-star-transformation-star-delta-transformation/#:~:text=The%20relation%20of%20delta%20%E2%80%93%20star,of%20the%20delta%20connected%20resistances. |
| 2 | +# https://en.wikipedia.org/wiki/Y-%CE%94_transform |
| 3 | + |
| 4 | + |
| 5 | +def star_to_delta( |
| 6 | + impedance_a: complex, |
| 7 | + impedance_b: complex, |
| 8 | + impedance_c: complex, |
| 9 | +) -> list[complex]: |
| 10 | + """ |
| 11 | +
|
| 12 | + Convert's star impedance arrangement to delta |
| 13 | +
|
| 14 | + Examples: |
| 15 | + 1.) Impedance with resistances and zero reactance |
| 16 | + >>> star_to_delta(complex(2,0),complex(1,0),complex(1,0)) |
| 17 | + [(2.5+0j), (5+0j), (5+0j)] |
| 18 | +
|
| 19 | + 2.) Impedance with resistance and reactance |
| 20 | + >>> star_to_delta(complex(2,0),complex(1,2),complex(1,6)) |
| 21 | + [(-3.5+12j), (8.2+7.6j), (3.702702702702702+1.7837837837837838j)] |
| 22 | +
|
| 23 | + 3.) Zero impedance |
| 24 | + >>> star_to_delta(complex(0,0),complex(1,2),complex(1,6)) |
| 25 | + Traceback (most recent call last): |
| 26 | + ... |
| 27 | + ValueError: entered impedance value is zero |
| 28 | +
|
| 29 | + 4.) Negative resistance |
| 30 | + >>> star_to_delta(complex(12,0),complex(-1,2),complex(1,6)) |
| 31 | + Traceback (most recent call last): |
| 32 | + ... |
| 33 | + ValueError: entered resistance value is negative |
| 34 | + """ |
| 35 | + |
| 36 | + if abs(impedance_a) == 0 or abs(impedance_b) == 0 or abs(impedance_c) == 0: |
| 37 | + raise ValueError("entered impedance value is zero") |
| 38 | + |
| 39 | + if impedance_a.real < 0 or impedance_b.real < 0 or impedance_c.real < 0: |
| 40 | + raise ValueError("entered resistance value is negative") |
| 41 | + |
| 42 | + delta_arrangement = [] |
| 43 | + impedance_chain = ( |
| 44 | + impedance_a * impedance_b |
| 45 | + + impedance_b * impedance_c |
| 46 | + + impedance_c * impedance_a |
| 47 | + ) |
| 48 | + delta_arrangement.append(impedance_chain / impedance_a) |
| 49 | + delta_arrangement.append(impedance_chain / impedance_b) |
| 50 | + delta_arrangement.append(impedance_chain / impedance_c) |
| 51 | + |
| 52 | + return delta_arrangement |
| 53 | + |
| 54 | + |
| 55 | +def delta_to_star( |
| 56 | + impedance_a: complex, |
| 57 | + impedance_b: complex, |
| 58 | + impedance_c: complex, |
| 59 | +) -> list[complex]: |
| 60 | + """ |
| 61 | +
|
| 62 | + Convert's delta impedance arrangement to star |
| 63 | +
|
| 64 | + Examples: |
| 65 | + 1.) Impedance with resistances and zero reactance |
| 66 | + >>> delta_to_star(complex(3,0),complex(5,0),complex(7,0)) |
| 67 | + [(2.3333333333333335+0j), (1.4+0j), (1+0j)] |
| 68 | +
|
| 69 | + 2.) Impedance with resistance and reactance |
| 70 | + >>> delta_to_star(complex(1,3),complex(2,0),complex(0,-3)) |
| 71 | + [-2j, (3-1j), (0.6666666666666666+2j)] |
| 72 | +
|
| 73 | + 3.) Zero impedance |
| 74 | + >>> delta_to_star(complex(0,0),complex(1,2),complex(1,6)) |
| 75 | + Traceback (most recent call last): |
| 76 | + ... |
| 77 | + ValueError: entered impedance value is zero |
| 78 | +
|
| 79 | + 4.) Negative resistance |
| 80 | + >>> delta_to_star(complex(12,0),complex(-1,2),complex(1,6)) |
| 81 | + Traceback (most recent call last): |
| 82 | + ... |
| 83 | + ValueError: entered resistance value is negative |
| 84 | + """ |
| 85 | + if abs(impedance_a) == 0 or abs(impedance_b) == 0 or abs(impedance_c) == 0: |
| 86 | + raise ValueError("entered impedance value is zero") |
| 87 | + |
| 88 | + if impedance_a.real < 0 or impedance_b.real < 0 or impedance_c.real < 0: |
| 89 | + raise ValueError("entered resistance value is negative") |
| 90 | + |
| 91 | + star_arrangement = [] |
| 92 | + impedance_sum = impedance_a + impedance_b + impedance_c |
| 93 | + star_arrangement.append((impedance_b * impedance_c) / impedance_sum) |
| 94 | + star_arrangement.append((impedance_c * impedance_a) / impedance_sum) |
| 95 | + star_arrangement.append((impedance_a * impedance_b) / impedance_sum) |
| 96 | + |
| 97 | + return star_arrangement |
| 98 | + |
| 99 | + |
| 100 | +if __name__ == "__main__": |
| 101 | + import doctest |
| 102 | + |
| 103 | + doctest.testmod() |
0 commit comments