Polygon spirals

Polygon spirals

hobby2005
Explorer Explorer
781 Views
2 Replies
Message 1 of 3

Polygon spirals

hobby2005
Explorer
Explorer

hi im designing a custom heating element in the shape of a polygon spiral   example bellow      imagine a car that  drives forward and turns the exterior angle of the polygon you want each time it turns it reduces the amount it drives forward by a fixed amount  that's how I understand these are made. How to draw spiral square and star in Python Turtle?      now I'm not a coder and literally almost know **** about python about coding beyond scratch 

 

i was wondering if anyone could help me out by either providing some code/  how to do this ,  make a simple plugin  or just give me a completed file 

 

ps.  drawing each line traditionally in fusion is not really a solution as its a pretty long spiral 

 

here's the specs on the spiral I'm trying to make     all units mm 

 

the shape is a octagon 

 

exterior octogon  has a side length of  307. 346

 

interor octogon side length of 173.205

 

the total length of the spiral is about 70 meters ( calculated using arithmetic sum      sum= steps/2 (a1 +a2) )

 

the decay or decrease of each side is 0.46 mm 

 

spacing between each  coil  is  5.932

 

to someone with even basic coding skills this should be trival  

 

thanks !spir.JPG

0 Likes
782 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor

I couldn't resist and had to give this a try.  Here are some of my results using different settings.

PolygonSamples.png

 Below is the code used to create them.  I didn't bother to create a nice interface and instead, there are some variables you'll need to change the values of to define the size and shape.  startLength defines the length of the first line.  decay is how much shorter the line gets as each line is drawn.  Both of these are in centimeters.  numSides is the number of sides in the polygon.  The examples above use 8, 8, 3, and 12.

 

#Author-
#Description-

import adsk.core, adsk.fusion, traceback
import math

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des: adsk.fusion.Design = app.activeProduct
        root = des.rootComponent

        # Create a new sketch on the base X-Y construction plane.
        sk: adsk.fusion.Sketch = root.sketches.add(root.xYConstructionPlane)

        # Define the parameters controlling the shape.
        startLength = 100
        decay = 1
        numSides = 8

        # Get the SketchLines collection, which supports the ability to create new lines.
        lines = sk.sketchCurves.sketchLines

        # Defer the sketch compute.  This will improve the performance.
        sk.isComputeDeferred = True
 
        sideLength = startLength
        lastLine: adsk.fusion.SketchLine = None
        lineCount = 0
        while sideLength > 0:
            # Compute the current angle based on the number of lines drawn so far.
            angle = ((math.pi * 2) / numSides) * (lineCount % numSides)
            if lastLine is None:
                # For the first line, define the starting point at the origin.
                startPoint = adsk.core.Point3D.create(0, 0, 0)
                startCoord = startPoint
            else:
                # For subsequent lines, the start point is the end of the last line.
                # Using the sketch point of the last line will also connect the lines.
                startPoint = lastLine.endSketchPoint
                startCoord = startPoint.geometry

            # Calculate the end point based on the start point and the current angle.
            endPoint = adsk.core.Point3D.create(startCoord.x + (sideLength * math.cos(angle)),
                                                startCoord.y + (sideLength * math.sin(angle)))

            # Draw the line and call doEvents to allow Fusion to render the line. Rendering it
            # isn't necessary and actually increases the time but it makes it more fun to watch.
            lastLine = lines.addByTwoPoints(startPoint, endPoint)
            adsk.doEvents()

            # Change the side length for the next line and increment the count.
            sideLength -= decay
            lineCount += 1           

        # Turn the sketch compute back on.
        sk.isComputeDeferred = False
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3

hobby2005
Explorer
Explorer

hi  it is pretty cool isn't it ?     well between posting this and your reply I actually drew this using python turtle 

 

its a bit low resolution but hey it worked!

 

 

at least if I or anyone else wants to do it they have a bit better solution than mine 

 

 

 

 

0 Likes