How to draft a golden spiral with Salome?

#!/usr/bin/env python

import salome
salome.salome_init()

import GEOM
from salome.geom import geomBuilder
import math

geompy = geomBuilder.New()

# ------------------------------------------------------------
# Golden Spiral Parameters
# ------------------------------------------------------------

TURNS = 3.0          # Number of turns
R0 = 1000.0            # Initial radius
NPTS = 500           # Number of sample points

phi = (1 + math.sqrt(5)) / 2
b = (2 * math.log(phi)) / math.pi

# ------------------------------------------------------------
# Generate points along the spiral
# ------------------------------------------------------------

points = []
t_max = 2 * math.pi * TURNS

for i in range(NPTS):
    t = t_max * i / (NPTS - 1)
    r = R0 * math.exp(b * t)
    x = r * math.cos(t)
    y = r * math.sin(t)
    z = 0.0
    p = geompy.MakeVertex(x, y, z)
    points.append(p)

# ------------------------------------------------------------
# Create polyline curve through the points
# ------------------------------------------------------------

spiral_curve = geompy.MakePolyline(points)

# ------------------------------------------------------------
# Add to study and update browser
# ------------------------------------------------------------

geompy.addToStudy(spiral_curve, "Golden_Spiral")

if salome.sg.hasDesktop():
    salome.sg.updateObjBrowser()


So far this script seems to run however nothing seems to show up in the drawing area when I have the geometry dashboard selected and am looking from “top view”….

What went wrong with the creation of the golden spiral?

to display the spiral_curve, you can either do it interactively by clicking on the Show/Hide icon on its left in the object browser. You can also do it programmatically as shown in the small code snippet below:

# retrieve the study entry of the published shape in form of string
spiral_id = geompy.addToStudy(spiral_curve, "Golden_Spiral")
if salome.sg.hasDesktop():
    salome.sg.updateObjBrowser()
    salome.sg.Display(spiral_id)
    salome.sg.FitAll()
    salome.sg.UpdateView()

See examples in the user documentation at this link.

1 Like