Skip to content

Commit c4e2c30

Browse files
authored
Update helper.py
Added create_noisy_circle_curve() function which is used in the basic wood classes in the envy model
1 parent 0f0e1fa commit c4e2c30

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

helper.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from openalea.plantgl.all import NurbsCurve
22
from 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

57
def 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

Comments
 (0)