-
Notifications
You must be signed in to change notification settings - Fork 8
/
square.py
69 lines (57 loc) · 1.97 KB
/
square.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import math
from math import pi
import KicadModTree as kmt
def delta_r(params):
# the change of radius at each step
if params.n_turns > 1:
delta_r = (params.r_outer - params.r_inner) / (params.n_turns - 1)
else: # for one turn this is needed not to close the square
delta_r = 2 * params.line_width
return delta_r
def coil_lines(params, direction=+1):
"""
Creates a square spiral coil.
It is assumed that we want to fill as much space as possible,
and so the length of line is shortened only after full turn.
The coil starts at corner of the square and ends in "previous"
corner.
"""
n_turns = int(params.n_turns)
if abs(n_turns - params.n_turns) > 0.01:
print('[WARNING] square coil can only have integer number of turns;'
' reducing n_turns to %d' % n_turns)
points = []
points.append((params.r_outer, - params.r_outer))
for i in range(n_turns):
r = params.r_outer - i * delta_r(params)
next_r = r - delta_r(params)
if direction > 0:
turn_points = [
(-r, -r),
(-r, r),
(r, r),
(r, -next_r),
]
else:
turn_points = [
(r, r),
(-r, r),
(-r, -r),
(next_r, -r),
]
points.extend(turn_points)
lines = []
for i in range(len(points) - 1):
lines.append(kmt.Line(start=points[i], end=points[i + 1],
width=params.line_width, layer='F.Cu'))
start_point = points[0]
end_point = points[-1]
return lines, start_point, end_point
def line_spacing(params):
"""
Calculates the space left between subsequent lines of the coil.
This is effectively the space between copper paths, so it should
be high enough to avoid electrical interference.
Negative spacing is...too small.
"""
return delta_r(params) - params.line_width