ex03_curve
This is an example for a scripted ‘curve’ element. A parametric function is used to create a 3-dimensional curve - a helix - with a fixed number of points. np.arange()
is used to iterate from t_min
to t_max
with a non-integer step size.
Note
Please see offset_point_v2.md for a complete scripted elements example with detailed description.
Source code excerpt
1import math
2import numpy as np
3
4def dialog(context, params):
5 #[...]
6
7def calculation(context, params):
8 valid_results = False
9
10 # Calculating all available stages
11 for stage in context.stages:
12 # Access element properties with error handling
13 try:
14 # Creating a list of points using a parametric curve function:
15 # P(t) = ( x0 + (j * t + r) * cos(t), y0 + (j * t + r) * cos(t), z0 + k * t )
16 # with t in [t_min...t_max], 1000 steps
17 points = []
18 for t in np.arange(params['t_min'], params['t_max'], (params['t_max'] - params['t_min']) / 1000):
19 points.append((params['x0'] + (params['j'] * t + params['radius']) * math.cos(t),
20 params['y0'] + (params['j'] * t + params['radius']) * math.sin(t),
21 params['z0'] + params['k'] * t)
22 )
23 context.result[stage] = [{'points': points}]
24 context.data[stage] = {"ude_mykey": "Example 3"}
25 except Exception as error:
26 context.error[stage] = str(error)
27 else:
28 valid_results = True
29 return valid_results