From aa9e328944bd1a21844b5834566298324558ed6d Mon Sep 17 00:00:00 2001 From: Chris Greening Date: Sun, 9 Oct 2022 20:56:02 +0100 Subject: [PATCH] Simplify template code --- coil_generator.ipynb | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/coil_generator.ipynb b/coil_generator.ipynb index 5032697..0643baa 100644 --- a/coil_generator.ipynb +++ b/coil_generator.ipynb @@ -105,7 +105,8 @@ "metadata": {}, "outputs": [], "source": [ - "template_f = [\n", + "# templates must be simetric around the X axis and must include the center points on both size (e.g. (X1, 0).... (X2, 0) )\n", + "template = [\n", " (-0.6, 0),\n", " (-0.6, -0.6),\n", " (0.5, -1.2),\n", @@ -114,12 +115,7 @@ " (0.95, 0.4),\n", " (0.5, 1.2),\n", " (-0.6, 0.6),\n", - "]\n", - "\n", - "template_b = []\n", - "for i in range(len(template_f)):\n", - " template_b.append(template_f[len(template_f) - i - len(template_f) // 2])\n", - "template_b = flip_x(template_b)" + "]" ] }, { @@ -129,11 +125,9 @@ "outputs": [], "source": [ "# plot the template shape wrapping around to the first point\n", - "df = pd.DataFrame(template_f + [template_f[0]], columns=[\"x\", \"y\"])\n", + "df = pd.DataFrame(template + [template[0]], columns=[\"x\", \"y\"])\n", "ax = df.plot.line(x=\"x\", y=\"y\", color=\"blue\")\n", - "ax.axis(\"equal\")\n", - "df = pd.DataFrame(template_b + [template_b[0]], columns=[\"x\", \"y\"])\n", - "ax = df.plot.line(x=\"x\", y=\"y\", color=\"red\", ax=ax)" + "ax.axis(\"equal\")" ] }, { @@ -142,7 +136,7 @@ "metadata": {}, "outputs": [], "source": [ - "def calculate_point(point, point1, point2, spacing, turn, layer):\n", + "def calculate_point(point, point1, point2, spacing, turn):\n", " reference_vector = Vector([-100, 0])\n", " angle = np.rad2deg(Vector(point).angle_between(reference_vector))\n", " if point[1] > 0:\n", @@ -157,7 +151,7 @@ " return (coil_point[0], coil_point[1])\n", "\n", "\n", - "def get_points(template, turns, spacing, layer=Layer.FRONT):\n", + "def get_points(template, turns, spacing):\n", " coil_points = []\n", " reference_vector = Vector([-100, 0])\n", " template_index = 0\n", @@ -168,15 +162,10 @@ "\n", " # calculate the new positions of the points\n", " coil_point1 = calculate_point(\n", - " point1, point1, point2, spacing, template_index // template_length, layer\n", + " point1, point1, point2, spacing, template_index // template_length\n", " )\n", " coil_point2 = calculate_point(\n", - " point2,\n", - " point1,\n", - " point2,\n", - " spacing,\n", - " (template_index + 1) // template_length,\n", - " layer,\n", + " point2, point1, point2, spacing, (template_index + 1) // template_length\n", " )\n", " # add an intermediate point which is the intersection of this new line with the previous line (if there is one)\n", " if len(coil_points) >= 2:\n", @@ -250,19 +239,18 @@ "outputs": [], "source": [ "if not USE_SPIRAL:\n", + " template_f = []\n", + " for i in range(len(template)):\n", + " template_f.append(template[len(template) - i - len(template) // 2])\n", + " template_f = flip_x(template_f)\n", " points_f = chaikin(\n", " optimize_points(\n", - " flip_x(\n", - " get_points(template_b, TURNS, TRACK_SPACING + TRACK_WIDTH, Layer.FRONT)\n", - " )\n", + " flip_x(get_points(template_f, TURNS, TRACK_SPACING + TRACK_WIDTH))\n", " ),\n", " 2,\n", " )\n", " points_b = chaikin(\n", - " optimize_points(\n", - " get_points(template_f, TURNS, TRACK_SPACING + TRACK_WIDTH, Layer.BACK)\n", - " ),\n", - " 2,\n", + " optimize_points(get_points(template, TURNS, TRACK_SPACING + TRACK_WIDTH)), 2\n", " )\n", "\n", " points_f = [(0, 0)] + points_f\n",