Added and fixed speira (archimedian spiral)

This commit is contained in:
Mario Voigt 2020-08-01 00:08:22 +02:00
parent 327b3a187e
commit 2d4d886b10
2 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>The Spiral of Archimedes</_name>
<id>fablabchemnitz.de.archimedesspiral</id>
<param name="name" appearance="header" type="description">R = r + aθ</param>
<param name="r" type="int" min="0" max="1000000" _gui-text="r (mm)">50</param>
<param name="a" type="float" min="0" max="1000000" _gui-text="a">3</param>
<param name="step" type="int" min="1" max="300" _gui-text="Step">50</param>
<param name="trl" type="optiongroup" _gui-text="Turn direction">
<option value="0">Left</option>
<option value="1">Right</option>
</param>
<param name="length" type="float" min="0" max="1000000" _gui-text="Length (mm)">0</param>
<param name="turns" type="int" min="1" max="1000000" _gui-text="Turns">5</param>
<param name="desc" appearance="header" type="description">Notes</param>
<param name="desc_text" type="description">
The option "turns" only works if you set "length (mm)" to 0.0.
Otherwise the length value will be used to calculate the
spiral for given length. The higher the "step" value is
set the better the accuracy is. If you set the step value
really low the resulting length will not be precise and
the curve is maybe not drawn at all. You can validate the
length by using the extension "Visualize Path > Measure Path"
</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu _name="FabLab Chemnitz">
<submenu _name="Shape/Pattern from Generator" />
</submenu>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">fablabchemnitz_archimedesspiral.py</command>
</script>
</inkscape-extension>

View File

@ -0,0 +1,87 @@
#!/usr/bin/env python3
"""
Copyright (C) 2017 Panagiotis Loukas
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WAphiANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WAphiANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Version 0.2
This script was written by Panagiotis Loukas to make spiral easy.
It simply,
Have fun :)
PS.
Written on Arch.
"""
import inkex
from lxml import etree
from math import cos, sin, pi, log, sqrt
class Archimedes(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
self.arg_parser.add_argument('--r', type = int, default = '50')
self.arg_parser.add_argument('--a', type = float, default = '3')
self.arg_parser.add_argument('--step', type = int, default = '50')
self.arg_parser.add_argument('--trl', default = '1')
self.arg_parser.add_argument('--turns', type = float, default = '5')
self.arg_parser.add_argument('--length', type = float, default = '500')
def effect(self):
th = pi / 3
a = self.options.a
r = self.options.r
length = self.options.length
if length > 0:
turns = self.angle(a, r, length, th) / (2 * pi)
else:
turns = self.options.turns
if self.options.trl == '1':
step = -self.options.step
else:
step = self.options.step
layer = etree.SubElement(self.document.getroot(),'g')
path = etree.Element(inkex.addNS('path','svg'))
path.set('d', self.built(r, step, a, turns))
path.set('style',"opacity:0.8;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.8;stroke-miterlimit:4;stroke-dashaphiay:none;stroke-opacity:1")
layer.append(path)
def built(self, r0, st = 4, a = 4, k = 1, th = 0):
step = 2 * pi / st
r = r0
s = "M " + str(r * cos(th)) + ", " + str(-r * sin(th))
for i in range(0, int(k * (abs(st)))):
prin = th + i * step
meta = th + (i + 1) * step
rp = r0 + abs(a * prin)# instead we put the absolute value the spiral will drift inwards
rm = r0 + abs(a * meta)# at the absolute price closes outwards
s += "a " + str(rm) + "," + str(rm) + " 0 0," + self.options.trl + " " + str(-rp * cos(prin) + rm * cos(meta)) + "," + str(rp * sin(prin) -rm * sin(meta))
return s
# see https://mathepedia.de/Archimedische_Spirale.html for formula of total arc length
def spirallength(self, a, r0, th):
phi = (r0 / a) + th
phi_sqrt = sqrt(phi ** 2 + 1)
return (a / 2) * (phi * phi_sqrt + log(phi + phi_sqrt))
def ds(self, a, r0, th):
return self.spirallength(a, r0, th) - self.spirallength(a, r0, 0)
def angle(self, a, r0, length, th):
i = 0.0
while (True):
ls=self.ds(a, r0, i)
if length - ls > 100:
i += 0.01
elif length - ls > 10: i += 0.001
elif length - ls > 1: i += 0.0001
elif length - ls > 0.1: i += 0.00001
elif length - ls > 0.01: i += 0.000001
else: break
return i
Archimedes().run()