thank you bobecka,
That is extremely fast code. I have changed it a bit because I needed two spirals with 4 mm in between. Also the variable ‘a’ is not the distance between revolutions but the distance from the center to the start of the spiral. I have not figured out how to set the distance between revolutions yet.
require 'sketchup.rb'
module Spiral
module DrawSpiral
def self.create_spiral
model = Sketchup.active_model
model.start_operation('create spiral', true)
# Setting the parameters of the Archimedean spiral
a1 = 10.mm # Starting point from the center
a2 = 14.mm # Starting point from the center
b = 0.1 # Angular step
num_points = 2000
theta = 0
# Create an array to store spiral points
points1 = []
points2 = []
# Calculate the coordinates of the spiral points
num_points.times do
r1 = a1 + b * theta
r2 = a2 + b * theta
x1 = r1 * Math.cos(theta)
y1 = r1 * Math.sin(theta)
x2 = r2 * Math.cos(theta)
y2 = r2 * Math.sin(theta)
z = 0 # We are building a spiral in the XY plane
points1 << [x1, y1, z]
points2 << [x2, y2, z]
theta += b
end
# We build lines between the points of the spiral
model.entities.add_curve(points1)
model.entities.add_curve(points2)
model.commit_operation
end # def
unless file_loaded?(__FILE__)
menu = UI.menu('Plugins')
menu.add_item('Create spiral') {
self.create_spiral
}
file_loaded(__FILE__)
end # unless
end # module DrawSpiral
end # module Spiral