圖、原始項目地址:https://github.com/Ro3code/aircraft_3d_animation
(點擊閱讀原文直接跳轉!)
飛機3D動畫功能
輕量級 MATLAB ®,可輕鬆可視化非線性飛行動力學模擬器的飛行測試數據記錄和輸出。
要下載官方版本和評價函數功能,請訪問其在Mathworks公司的文件交換站頁面。
https://www.mathworks.com/matlabcentral/fileexchange/86453-aircraft-3d-animation/?s_tid=mlc_lp_leaf
下載地址:
https://github.com/Ro3code/aircraft_3d_animation/archive/v1.1.zip
https://github.com/Ro3code/aircraft_3d_animation/archive/v1.1.tar.gz
提取 ZIP 文件(或克隆 git 存儲庫)到您輕鬆到達的位置。
在 MATLAB 中將文件夾添加到路徑:例如src/
只需將飛行測試或模擬數據饋送至函數,如下所示:aircraft_3d_animation
%% Example script to visualize the aircraft simulation data
% Add the path of the aircraft_3d_animation function
addpath('../src/');
% path of the *.mat file containing the 3d model information
model_info_file = 'saab_gripen_3d_model.mat';
% Load the simulation data
load('scissors_maneuver.mat')
% load('breakaway_maneuver.mat')
% load('split_s_maneuver.mat')
% define the reproduction speed factor
speedx = 1;
% Do you want to save the animation in a mp4 file? (0.No, 1.Yes)
isave_movie = 0;
% Movie file name
movie_file_name = '';
% ---
% The frame sample time shall be higher than 0.02 seconds to be able to
% update the figure (CPU/GPU constraints)
frame_sample_time = max(0.02, tout(2)-tout(1));
% Resample the time vector to modify the reproduction speed
t_new = tout(1):frame_sample_time*(speedx):tout(end);
% Resample the recorded data
act = interp1(tout, act, t_new','linear');
stick = interp1(tout, stick, t_new','linear');
y_new = interp1(tout, yout, t_new','linear');
% We have to be careful with angles with ranges
y_new(:, 7) = atan2(interp1(tout, sin(yout(:, 7)), t_new','linear'), interp1(tout, cos(yout(:, 7)), t_new','linear')) * 180 / pi;
y_new(:, 8) = atan2(interp1(tout, sin(yout(:, 8)), t_new','linear'), interp1(tout, cos(yout(:, 8)), t_new','linear')) * 180 / pi;
y_new(:, 9) = atan2(interp1(tout, sin(yout(:, 9)), t_new','linear'), interp1(tout, cos(yout(:, 9)), t_new','linear')) * 180 / pi;
% Assign the data
heading_deg = y_new(:, 7);
pitch_deg = y_new(:, 8);
bank_deg = y_new(:, 9);
roll_command = -stick(:, 2);
pitch_command = -stick(:, 1);
angle_of_attack_deg = y_new(:, 2) * 180 / pi;
angle_of_sideslip_deg = y_new(:, 3) * 180 / pi;
fligh_path_angle_deg = y_new(:, 22) * 180 / pi;
mach = y_new(:, 21);
altitude_ft = -y_new(:, 12);
nz_g = y_new(:, 19);
% Flight control surfaces
le = act(:, 9);
dr = act(:, 8);
df1 = act(:, 6);
df2 = act(:, 5);
df3 = act(:, 4);
df4 = act(:, 3);
dfp = 0.5 * (act(:, 1) + act(:, 2));
% Control array assignation
% (modify the order according to your particular 3D model)
controls_deflection_deg = [0.5*(df1(:)+df2(:)), 0.5*(df3(:)+df4(:)), le(:), le(:), dr(:), dfp(:), dfp(:)];
%% Run aircraft_3d_animation function
% ---
aircraft_3d_animation(model_info_file,...
heading_deg, ... Heading angle [deg]
pitch_deg, ... Pitch angle [deg]
bank_deg, ... Roll angle [deg]
roll_command, ... Roll stick command [-1,+1] [-1 -> left, +1 -> right]
pitch_command, ... Pitch stick command [-1,+1] [-1 -> full-back stick, +1 -> full-fwd stick]
angle_of_attack_deg, ... AoA [deg]
angle_of_sideslip_deg, ... AoS [deg]
fligh_path_angle_deg, ... Flight path angle [deg]
mach, ... Mach number
altitude_ft, ... Altitude [ft]
nz_g, ... Vertical load factor [g]
controls_deflection_deg, ...Flight control deflection (each column is a control surface)
frame_sample_time, ... Sample time [sec]
speedx, ... Reproduction speed
isave_movie, ... Save the movie? 0-1
movie_file_name); % Movie file name
您需要做的第一件事是尋找一個 3D 模型在 *.stl 格式 (STereoLithography), 最好地代表飛機或航空器的外部幾何。
有各種各樣的網頁,你可以找到一個無窮的3D模型免費下載。我建議你看看下面的網站,你一定會找到你正在尋找的3D模型:
由於功能允許對飛機的移動部件進行動畫處理,因此首先,您必須將 3D 模型分成兩組部件/子模型:牢固地連接到主體的剛性部件(機身、機翼、駕駛艙等),以及可圍繞主體移動和/或旋轉的部件(飛行控制表面、起落架等) 的一組部件。
您可以使用任何3D編輯工具來分割模型的可移動飛行控制表面,我個人喜歡S網實驗室,因為它易於使用,最重要的是,它是完全免費的。
https://www.meshlab.net/
有關如何實現自己的 3D 模型的更多信息,請查看import_stl_model文件夾。
https://github.com/Ro3code/aircraft_3d_animation/tree/main/import_stl_model
快去試試吧!
喜歡就點個在看吧!