I have written code to divide the curve into short segments according to the entered quantity and approximately at a ratio of the next line equal to the previous line multiplied by the entered ratio. but the code only works properly with straight line objects. Curve objects do not work properly
<# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs
def create_points_along_curve_with_ratio(curve, ratio, num_points):
points = []
total_length = rs.CurveLength(curve)
t = 1.0
a = [t]
for i in range(num_points-1):
t = t * ratio
a.append(t)
if ratio <= 0 or num_points <= 0:
print("The ratio and the number of points must be greater than 0.")
return points
t_step = total_length / sum(a)
t = 1.0
for i in range(num_points):
point = curve.PointAt(t_step * t)
print(t_step * t)
points.append(point)
if i == num_points - 1:
break
t = t * ratio + 1
print(t)
return points
def RunCommand():
curve_id = rs.GetObject("Select a curve", rs.filter.curve)
if not curve_id:
return
curve = rs.coercecurve(curve_id)
if curve is None or rs.CurveLength(curve) < rs.UnitAbsoluteTolerance():
return
ratio = rs.GetReal("Enter the ratio for division (e.g., 0.5 for halves):")
num_points = rs.GetInteger("Enter the number of points:")
points = create_points_along_curve_with_ratio(curve, ratio, num_points)
if points:
for point in points:
rs.AddPoint(point)
rs.Redraw()
if __name__ == "__main__":
RunCommand()>