@@ -94,16 +94,50 @@ def calc_naca4_points(number, npoint, open_trailing_edge=False,
94
94
return ret
95
95
96
96
97
- def draw_naca4 (world , number , npoint , fac , off_x , off_y , ** kw ):
97
+ def calc_sample_points (points ):
98
+ # determine the number of sample points for a cubic bezier curve
99
+ spacing = 0.01
100
+ segments = np .hypot ((points [:- 1 , 0 ] - points [1 :, 0 ]),
101
+ (points [:- 1 , 1 ] - points [1 :, 1 ])) // spacing
102
+ nsample = np .where (segments > 2 , segments - 1 , 2 ).astype (int )
103
+ return nsample
104
+
105
+
106
+ def linear_approximate (world , points ):
107
+ for it in range (points .shape [0 ] - 1 ):
108
+ world .add_edge (points [it , 0 ], points [it , 1 ], 0 ,
109
+ points [it + 1 , 0 ], points [it + 1 , 1 ], 0 )
110
+ return
111
+
112
+
113
+ def cubic_bezier_approximate (world , points , nsample = None ):
114
+ Vector = core .Vector3dFp64
115
+
116
+ if nsample is None :
117
+ nsample = calc_sample_points (points )
118
+ for it in range (points .shape [0 ] - 1 ):
119
+ p1 = points [it ] + (1 / 3 ) * (points [it + 1 ] - points [it ])
120
+ p2 = points [it ] + (2 / 3 ) * (points [it + 1 ] - points [it ])
121
+
122
+ b = world .add_bezier ([Vector (points [it , 0 ], points [it , 1 ], 0 ),
123
+ Vector (p1 [0 ], p1 [1 ], 0 ),
124
+ Vector (p2 [0 ], p2 [1 ], 0 ),
125
+ Vector (points [it + 1 , 0 ], points [it + 1 , 1 ], 0 )])
126
+ b .sample (nsample [it ])
127
+ return
128
+
129
+
130
+ def draw_naca4 (world , number , npoint , fac , off_x , off_y ,
131
+ use_bezier = False , ** kw ):
98
132
crds = calc_naca4_points (number = number , npoint = npoint , ** kw )
99
133
crds *= fac # scaling factor
100
134
crds [:, 0 ] += off_x # offset in x
101
135
crds [:, 1 ] += off_y # offset in y
102
- for it in range ( crds . shape [ 0 ] - 1 ):
103
- e = world . add_edge ( crds [ it , 0 ], crds [ it , 1 ], 0 ,
104
- crds [ it + 1 , 0 ], crds [ it + 1 , 1 ], 0 )
105
- print ( f" { it } : { e } " )
106
- print ( "nedge:" , world . nedge )
136
+
137
+ if use_bezier :
138
+ cubic_bezier_approximate ( world , crds )
139
+ else :
140
+ linear_approximate ( world , crds )
107
141
return crds
108
142
109
143
@@ -113,7 +147,7 @@ def runmain():
113
147
"""
114
148
w = core .WorldFp64 ()
115
149
draw_naca4 (w , number = '0012' , npoint = 101 , fac = 5.0 , off_x = 0.0 , off_y = 2.0 ,
116
- open_trailing_edge = False , cosine_spacing = True )
150
+ open_trailing_edge = False , use_bezier = True , cosine_spacing = True )
117
151
wid = view .mgr .add3DWidget ()
118
152
wid .updateWorld (w )
119
153
wid .showMark ()
0 commit comments