Skip to content

Commit b9597b9

Browse files
authored
Updated helper functions
1 parent b5dd7d4 commit b9597b9

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

helper.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from openalea.plantgl.all import NurbsCurve
1+
from openalea.plantgl.all import NurbsCurve, Vector3, Point2Array, Point3Array, Polyline2D, BezierCurve2D
22
from openalea.lpy import Lsystem, newmodule
33
from random import uniform, seed
44
from numpy import linspace, pi, sin, cos
@@ -8,8 +8,8 @@ def amplitude(x): return 2
88

99
def cut_from(pruning_id, s, path = None):
1010
"""Check cut_string_from_manipulation for manual implementation"""
11-
#s.insertAt(pruning_id, newmodule('F'))
12-
s.insertAt(pruning_id, newmodule('%'))
11+
s.insertAt(pruning_id, newmodule('F'))
12+
s.insertAt(pruning_id+1, newmodule('%'))
1313
return s
1414

1515
def cut_using_string_manipulation(pruning_id, s, path = None):
@@ -108,3 +108,20 @@ def create_noisy_circle_curve(radius, noise_factor, num_points=100, seed=None):
108108
curve_points = Point2Array(points)
109109
curve = Polyline2D(curve_points)
110110
return curve
111+
112+
def create_bezier_curve(num_control_points=4, x_range=(0, 10), y_range=(-2, 2), seed_val=None):
113+
if seed_val is not None:
114+
seed(seed_val) # Set the random seed for reproducibility
115+
# Generate progressive control points within the specified ranges
116+
control_points = []
117+
prev_x = uniform(x_range[0], x_range[1] / 4)
118+
for i in range(num_control_points):
119+
x = prev_x + uniform(0, (x_range[1] - prev_x) / (num_control_points - i))
120+
y = uniform(*y_range)
121+
control_points.append(Vector3(x, y, 0)) # Set z to 0 for 2D curve
122+
prev_x = x
123+
# Create a Point3Array from the control points
124+
control_points_array = Point3Array(control_points)
125+
# Create and return the BezierCurve2D object
126+
bezier_curve = BezierCurve2D(control_points_array)
127+
return bezier_curve

0 commit comments

Comments
 (0)