@@ -552,22 +552,45 @@ function _apply_refined_section_thetas!(wing::Wing{P, T}, section_thetas) where
552552 local_y = zeros (MVector{3 , T})
553553 chord = zeros (MVector{3 , T})
554554 normal = zeros (MVector{3 , T})
555+ n_sec = wing. n_panels + 1
555556
556- for i in 1 : (wing . n_panels + 1 )
557+ for i in 1 : n_sec
557558 theta = section_thetas[i]
558559 section = wing. non_deformed_sections[i]
559-
560- if i < wing. n_panels + 1
561- section2 = wing. non_deformed_sections[i + 1 ]
562- local_y .= normalize (section. LE_point - section2. LE_point)
563- else
564- section_prev = wing. non_deformed_sections[i - 1 ]
565- local_y .= normalize (section_prev. LE_point - section. LE_point)
560+ le = section. LE_point
561+
562+ # Spanwise axis: average of unit vectors to the left and right neighbour LE
563+ # points so curvature does not bias the twist axis. Boundaries fall back to
564+ # whichever side exists.
565+ local_y .= zero (T)
566+ if i > 1
567+ le_prev = wing. non_deformed_sections[i - 1 ]. LE_point
568+ dx = le_prev[1 ] - le[1 ]
569+ dy = le_prev[2 ] - le[2 ]
570+ dz = le_prev[3 ] - le[3 ]
571+ inv_n = 1 / sqrt (dx * dx + dy * dy + dz * dz)
572+ local_y[1 ] += dx * inv_n
573+ local_y[2 ] += dy * inv_n
574+ local_y[3 ] += dz * inv_n
575+ end
576+ if i < n_sec
577+ le_next = wing. non_deformed_sections[i + 1 ]. LE_point
578+ dx = le[1 ] - le_next[1 ]
579+ dy = le[2 ] - le_next[2 ]
580+ dz = le[3 ] - le_next[3 ]
581+ inv_n = 1 / sqrt (dx * dx + dy * dy + dz * dz)
582+ local_y[1 ] += dx * inv_n
583+ local_y[2 ] += dy * inv_n
584+ local_y[3 ] += dz * inv_n
566585 end
586+ inv_n = 1 / sqrt (local_y[1 ]^ 2 + local_y[2 ]^ 2 + local_y[3 ]^ 2 )
587+ local_y[1 ] *= inv_n
588+ local_y[2 ] *= inv_n
589+ local_y[3 ] *= inv_n
567590
568- chord .= section. TE_point .- section . LE_point
591+ chord .= section. TE_point .- le
569592 normal .= chord × local_y
570- @. wing. refined_sections[i]. TE_point = section . LE_point +
593+ @. wing. refined_sections[i]. TE_point = le +
571594 cos (theta) * chord - sin (theta) * normal
572595 end
573596 return nothing
0 commit comments