__author__ = "siddharth_chattoraj"
__version__ = "2024.05.03"

import rhinoscriptsyntax as rs  # rhino functionality
import math

# input
Height = Height * 10            # Convert to mm
BaseRadius = 5 * 10    # Convert base radius to mm
LayerHeight
TwistAngle = 360                # Total twist angle in degrees
BulgeFrequency = 5              # Number of bulges along the height
BulgeAmplitude = 10             # How much the radius increases at the bulge

# output
vertices = []

layerCount = int(Height / LayerHeight)
for i in range(layerCount):
    # Calculate radius variation with bulges
    bulgeFactor = math.sin(math.pi * i / layerCount * BulgeFrequency) * BulgeAmplitude
    currentRadius = BaseRadius + bulgeFactor

    circumference = math.pi * 2 * currentRadius   # Circumference of the layer
    pointCount = int(circumference * .5)          # One vertex every 2 mm
    for j in range(pointCount):
        ang = math.pi * 2 * j / pointCount
        ang += (TwistAngle / 360.0) * (math.pi * 2 * i / layerCount)  # Add twist
        inc = LayerHeight / pointCount             # Amount to raise each point
        x = math.cos(ang) * currentRadius          # Polar coordinates
        y = math.sin(ang) * currentRadius
        z = i * LayerHeight + j * inc
        vertices.append(rs.CreatePoint(x, y, z))
        if i % 2 == 0:
            vertices.append(rs.CreatePlane([x, 0, z]))
