@@ -155,8 +155,8 @@ function create_interpolations(vertices, circle_center_z, radius, gamma_tip)
155155 return (le_interp, te_interp, area_interp)
156156end
157157
158- # Calculate center of mass for a triangular surface mesh
159- function calculate_com (vertices, faces)
158+ # Makes the zero coordinates lie on the com
159+ function center_to_com! (vertices, faces)
160160 area_total = 0.0
161161 com = zeros (3 )
162162
@@ -174,7 +174,13 @@ function calculate_com(vertices, faces)
174174 com += area * centroid
175175 end
176176
177- return com / area_total
177+ com = com / area_total
178+ ! (abs (com[2 ]) < 0.01 ) && @warn " Center of mass $com has to lie on the xz-plane."
179+ @info " Centering vertices of .obj file to the center of mass: $com "
180+ for v in vertices
181+ v .- = com
182+ end
183+ return com
178184end
179185
180186"""
@@ -304,7 +310,6 @@ Represents a curved wing that inherits from Wing with additional geometric prope
304310 - refined_sections::Vector{Section}
305311 - `remove_nan::Bool`: Wether to remove the NaNs from interpolations or not
306312- Additional fields:
307- - `center_of_mass::Vector{Float64}`: Center of mass coordinates
308313 - `circle_center_z::Vector{Float64}`: Center of circle coordinates
309314 - gamma_tip::Float64: Angle between the body frame z axis and the vector going from the kite circular shape center to the wing tip.
310315 - `inertia_tensor`::Matrix{Float64}: see: [`calculate_inertia_tensor`](@ref)
@@ -325,7 +330,6 @@ mutable struct KiteWing <: AbstractWing
325330 # Additional fields for KiteWing
326331 non_deformed_sections:: Vector{Section}
327332 mass:: Float64
328- center_of_mass:: Vector{Float64}
329333 circle_center_z:: Float64
330334 gamma_tip:: Float64
331335 inertia_tensor:: Matrix{Float64}
@@ -378,14 +382,13 @@ function KiteWing(obj_path, dat_path; alpha=0.0, crease_frac=0.75, wind_vel=10.,
378382 if ! ispath (polar_path) || ! ispath (info_path)
379383 @info " Reading $obj_path "
380384 vertices, faces = read_faces (obj_path)
381- center_of_mass = calculate_com (vertices, faces)
382- ! (abs (center_of_mass[2 ]) < 0.01 ) && @error " Center of mass $center_of_mass has to lie on x-axis."
383- inertia_tensor = calculate_inertia_tensor (vertices, faces, mass, center_of_mass)
385+ center_to_com! (vertices, faces)
386+ inertia_tensor = calculate_inertia_tensor (vertices, faces, mass, zeros (3 ))
384387
385388 circle_center_z, radius, gamma_tip = find_circle_center_and_radius (vertices)
386389 le_interp, te_interp, area_interp = create_interpolations (vertices, circle_center_z, radius, gamma_tip)
387390 @info " Writing $info_path "
388- serialize (info_path, (center_of_mass, inertia_tensor, circle_center_z, radius, gamma_tip,
391+ serialize (info_path, (inertia_tensor, circle_center_z, radius, gamma_tip,
389392 le_interp, te_interp, area_interp))
390393
391394 width = 2 gamma_tip * radius
@@ -405,7 +408,7 @@ function KiteWing(obj_path, dat_path; alpha=0.0, crease_frac=0.75, wind_vel=10.,
405408 interpolate_matrix_nans! (cm_matrix)
406409 end
407410
408- (center_of_mass, inertia_tensor, circle_center_z, radius, gamma_tip,
411+ (inertia_tensor, circle_center_z, radius, gamma_tip,
409412 le_interp, te_interp, area_interp) = deserialize (info_path)
410413
411414 # Create sections
@@ -418,7 +421,7 @@ function KiteWing(obj_path, dat_path; alpha=0.0, crease_frac=0.75, wind_vel=10.,
418421 end
419422
420423 KiteWing (n_panels, spanwise_panel_distribution, spanwise_direction, sections, sections, remove_nan, sections,
421- mass, center_of_mass, circle_center_z, gamma_tip, inertia_tensor, radius,
424+ mass, circle_center_z, gamma_tip, inertia_tensor, radius,
422425 le_interp, te_interp, area_interp, zeros (n_panels), zeros (n_panels))
423426end
424427
0 commit comments