@@ -112,7 +112,8 @@ Create interpolation functions for leading/trailing edges and area.
112112- Where le_interp and te_interp are tuples themselves, containing the x, y and z interpolations
113113"""
114114function create_interpolations (vertices, circle_center_z, radius, gamma_tip, R= I (3 ); interp_steps= 40 )
115- gamma_range = range (- gamma_tip+ 1e-6 , gamma_tip- 1e-6 , interp_steps)
115+ gamma_range = range (- gamma_tip+ gamma_tip/ interp_steps* 2 ,
116+ gamma_tip- gamma_tip/ interp_steps* 2 , interp_steps)
116117 stepsize = gamma_range. step. hi
117118 vz_centered = [v[3 ] - circle_center_z for v in vertices]
118119
@@ -122,33 +123,91 @@ function create_interpolations(vertices, circle_center_z, radius, gamma_tip, R=I
122123 leading_edges = zeros (3 , length (gamma_range))
123124 areas = zeros (length (gamma_range))
124125
126+ n_slices = length (gamma_range)
125127 for (j, gamma) in enumerate (gamma_range)
126128 trailing_edges[1 , j] = - Inf
127129 leading_edges[1 , j] = Inf
128- for (i, v) in enumerate (vertices)
129- # Rotate y coordinate to check box containment
130- # rotated_y = v[2] * cos(-gamma) - vz_centered[i] * sin(-gamma)
131- gamma_v = atan (- v[2 ], vz_centered[i])
132- if gamma ≤ 0 && gamma - stepsize ≤ gamma_v ≤ gamma
133- if v[1 ] > trailing_edges[1 , j]
134- trailing_edges[:, j] .= v
135- te_gammas[j] = gamma_v
136- end
137- if v[1 ] < leading_edges[1 , j]
138- leading_edges[:, j] .= v
139- le_gammas[j] = gamma_v
130+
131+ # Determine if this is a tip slice and get search parameters
132+ is_first_tip = (j == 1 )
133+ is_last_tip = (j == n_slices)
134+
135+ if is_first_tip || is_last_tip
136+ # Tip slices: use directional search within adjacent slice region
137+ gamma_search = is_first_tip ? gamma_range[1 ] : gamma_range[end ]
138+ max_te_score = - Inf
139+ max_le_score = - Inf
140+
141+ for (i, v) in enumerate (vertices)
142+ gamma_v = atan (- v[2 ], vz_centered[i])
143+
144+ # Check if vertex is in the adjacent slice region
145+ in_range = if gamma_search ≤ 0
146+ gamma_search - stepsize ≤ gamma_v ≤ gamma_search
147+ else
148+ gamma_search ≤ gamma_v ≤ gamma_search + stepsize
140149 end
141- elseif gamma > 0 && gamma ≤ gamma_v ≤ gamma + stepsize
142- if v[1 ] > trailing_edges[1 , j]
143- trailing_edges[:, j] .= v
144- te_gammas[j] = gamma_v
150+
151+ if in_range
152+ if is_first_tip
153+ # TE: furthest in [X, Y, -Z] direction
154+ te_score = v[1 ] + v[2 ] - v[3 ]
155+ if te_score > max_te_score
156+ trailing_edges[:, j] .= v
157+ te_gammas[j] = gamma_v
158+ max_te_score = te_score
159+ end
160+ # LE: furthest in [-X, Y, -Z] direction
161+ le_score = - v[1 ] + v[2 ] - v[3 ]
162+ if le_score > max_le_score
163+ leading_edges[:, j] .= v
164+ le_gammas[j] = gamma_v
165+ max_le_score = le_score
166+ end
167+ else # is_last_tip
168+ # TE: furthest in [X, -Y, -Z] direction
169+ te_score = v[1 ] - v[2 ] - v[3 ]
170+ if te_score > max_te_score
171+ trailing_edges[:, j] .= v
172+ te_gammas[j] = gamma_v
173+ max_te_score = te_score
174+ end
175+ # LE: furthest in [-X, -Y, -Z] direction
176+ le_score = - v[1 ] - v[2 ] - v[3 ]
177+ if le_score > max_le_score
178+ leading_edges[:, j] .= v
179+ le_gammas[j] = gamma_v
180+ max_le_score = le_score
181+ end
182+ end
145183 end
146- if v[1 ] < leading_edges[1 , j]
147- leading_edges[:, j] .= v
148- le_gammas[j] = gamma_v
184+ end
185+ else
186+ # Interior slices: use standard min/max x-coordinate search
187+ for (i, v) in enumerate (vertices)
188+ gamma_v = atan (- v[2 ], vz_centered[i])
189+ if gamma ≤ 0 && gamma - stepsize ≤ gamma_v ≤ gamma
190+ if v[1 ] > trailing_edges[1 , j]
191+ trailing_edges[:, j] .= v
192+ te_gammas[j] = gamma_v
193+ end
194+ if v[1 ] < leading_edges[1 , j]
195+ leading_edges[:, j] .= v
196+ le_gammas[j] = gamma_v
197+ end
198+ elseif gamma > 0 && gamma ≤ gamma_v ≤ gamma + stepsize
199+ if v[1 ] > trailing_edges[1 , j]
200+ trailing_edges[:, j] .= v
201+ te_gammas[j] = gamma_v
202+ end
203+ if v[1 ] < leading_edges[1 , j]
204+ leading_edges[:, j] .= v
205+ le_gammas[j] = gamma_v
206+ end
149207 end
150208 end
151209 end
210+
152211 area = norm (leading_edges[:, j] - trailing_edges[:, j]) * stepsize * radius
153212 last_area = j > 1 ? areas[j- 1 ] : 0.0
154213 areas[j] = last_area + area
@@ -159,9 +218,9 @@ function create_interpolations(vertices, circle_center_z, radius, gamma_tip, R=I
159218 trailing_edges[:, j] .= R * trailing_edges[:, j]
160219 end
161220
162- le_interp = ntuple (i -> linear_interpolation (te_gammas , leading_edges[i, :],
221+ le_interp = ntuple (i -> linear_interpolation (le_gammas , leading_edges[i, :],
163222 extrapolation_bc= Line ()), 3 )
164- te_interp = ntuple (i -> linear_interpolation (le_gammas , trailing_edges[i, :],
223+ te_interp = ntuple (i -> linear_interpolation (te_gammas , trailing_edges[i, :],
165224 extrapolation_bc= Line ()), 3 )
166225 area_interp = linear_interpolation (gamma_range, areas, extrapolation_bc= Line ())
167226
0 commit comments