ex04_surface_curve
This is an example for a scripted ‘surface curve’ element. A parametric function is used to create a 3-dimensional surface curve - a section of a circle’s parallel - with a fixed number of definition points. These point vectors are used as normals, too. np.arange()
is used to iterate from phi_min
to phi_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
1def dialog(context, params):
2 #[...]
3
4def calculation(context, params):
5 valid_results = False
6
7 # Calculating all available stages
8 for stage in context.stages:
9 # Access element properties with error handling
10 try:
11 # Creating a list of points using a parametric curve function:
12 # P(t) = ( r * cos(theta) * cos(phi), r * cos(theta) * sin (phi), r * sin(phi) )
13 # with
14 # theta = const
15 # phi in [phi_min...phi_max], 1000 steps
16 points = []
17 normals = []
18 for phi in np.arange(params['phi_min'], params['phi_max'], (params['phi_max'] - params['phi_min']) / 1000):
19 p = (
20 params['r'] * math.cos(params['theta']) * math.cos(phi),
21 params['r'] * math.cos(params['theta']) * math.sin(phi),
22 params['r'] * math.sin(params['theta'])
23 )
24 points.append(p)
25 normals.append(p)
26 context.result[stage] = [{'points': points, 'normals': normals}]
27 context.data[stage] = {"ude_mykey": "Example 3b"}
28 except Exception as error:
29 context.error[stage] = str(error)
30 else:
31 valid_results = True
32 return valid_results