11from openalea .plantgl .all import NurbsCurve
22from openalea .lpy import Lsystem , newmodule
3- from random import uniform
3+ from random import uniform , seed
4+ from numpy import linspace , pi , sin , cos
5+
46
57def amplitude (x ): return 2
68
@@ -78,4 +80,31 @@ def gen_noise_branch(radius,nbp=20):
7880 return NurbsCurve ([(0 ,0 ,0 ,1 ),(0 ,0 ,1 / float (nbp - 1 ),1 )]+ [(myrandom (radius * amplitude (pt / float (nbp - 1 ))),
7981 myrandom (radius * amplitude (pt / float (nbp - 1 ))),
8082 pt / float (nbp - 1 ),1 ) for pt in range (2 ,nbp )],
81- degree = min (nbp - 1 ,3 ),stride = nbp * 100 )
83+ degree = min (nbp - 1 ,3 ),stride = nbp * 100 )
84+
85+ def create_noisy_circle_curve (radius , noise_factor , num_points = 100 , seed = None ):
86+ if seed is not None :
87+ seed (seed )
88+ t = linspace (0 , 2 * pi , num_points , endpoint = False )
89+ points = []
90+ for angle in t :
91+ # Base circle points
92+ x = radius * cos (angle )
93+ y = radius * sin (angle )
94+
95+ # Add noise
96+ noise_x = uniform (- noise_factor , noise_factor )
97+ noise_y = uniform (- noise_factor , noise_factor )
98+
99+ noisy_x = x + noise_x
100+ noisy_y = y + noise_y
101+
102+ points .append ((noisy_x , noisy_y ))
103+
104+ # Ensure the curve is closed by adding the first point at the end
105+ points .append (points [0 ])
106+
107+ # Create the PlantGL Point2Array and Polyline2D
108+ curve_points = Point2Array (points )
109+ curve = Polyline2D (curve_points )
110+ return curve
0 commit comments