From c865a9d7cb7329c823f795c223c69f6caf17eeae Mon Sep 17 00:00:00 2001 From: giuliaghirardini <giuliaghirardini2001@gmail.com> Date: Tue, 26 Nov 2024 11:09:38 +0100 Subject: [PATCH] [rocket-plot][Rocket] First implementation of rocket plot function, to be added in class --- classes/Rocket.m | 10 +++++ mainrocketplot.m | 52 ++++++++++++++++++++++ rocketPlot.m | 109 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+) create mode 100644 mainrocketplot.m create mode 100644 rocketPlot.m diff --git a/classes/Rocket.m b/classes/Rocket.m index 0088c2c..8a78fd6 100644 --- a/classes/Rocket.m +++ b/classes/Rocket.m @@ -348,6 +348,16 @@ classdef Rocket < Component end end + % function rocketPlot(obj) + % deltaXLE = obj.rear.finsDeltaXFreeChord; + % r = obj.diameter/2; + % height = obj.rear.finsHeight; + % C1 = obj.rear.finsRootChord; + % C2 = obj.rear.finsFreeChord; + % + % %%% still developing. this is just a try + % end + function checks = checkGeometry(obj) % checkGeometry - This methods checks if the rocket geometry % is consistent with the geometry of the diff --git a/mainrocketplot.m b/mainrocketplot.m new file mode 100644 index 0000000..b3b6816 --- /dev/null +++ b/mainrocketplot.m @@ -0,0 +1,52 @@ +close all +clear +clc + +%% +mission = Mission('design'); +mission2 = Mission('design'); + +rocket = Rocket(mission); +rocket2 = Rocket(mission2); + +r = rocketPlot(mission, rocket); +r2 = rocketPlot(mission2, rocket2); + +%% Merging Figures + +% Get axes from both figures +first_ax = findobj(r, 'type', 'axes'); +second_ax = findobj(r2, 'type', 'axes'); + +% Modify the appearance of the second rocket's plot +ch2 = get(second_ax, 'children'); % Get children of second figure's axes +for i = 1:length(ch2) + if isprop(ch2(i), 'Color') % Check if the child has a 'Color' property + set(ch2(i), 'Color', 'blue', 'LineStyle', '--'); % Set color to blue, dashed line + end +end + +% Create a new figure for the merged content +merged_fig = figure('Name', 'Merged Figure'); +merged_ax = axes(merged_fig); % Create new axes in the merged figure + +% Copy the children from the first figure's axes +ch1 = get(first_ax, 'children'); % Direct children only +copyobj(ch1, merged_ax); % Copy to merged axes + +% Copy the modified children from the second figure's axes +copyobj(ch2, merged_ax); % Copy to merged axes + +% Set up legend with correct colors +legend_labels = [ch1(1), ch2(1)]; % Use the first plot from each figure for the legend +legend(merged_ax, legend_labels, ... + {string(strrep(mission.name, '_', ' ')), string(strrep(mission2.name, '_', ' '))}, ... + 'Location', 'best'); + +% Adjust labels and appearance +xlabel(merged_ax, 'Merged X-axis Label'); +ylabel(merged_ax, 'Merged Y-axis Label'); +title('Rocket Comparison'); +axis equal + +disp('Figures merged successfully.'); diff --git a/rocketPlot.m b/rocketPlot.m new file mode 100644 index 0000000..c95019c --- /dev/null +++ b/rocketPlot.m @@ -0,0 +1,109 @@ +function roc = rocketPlot(mission, rocket) +arguments + mission Mission + rocket Rocket +end + deltaXLE = rocket.rear.finsDeltaXFreeChord; + r = rocket.diameter/2; + height = rocket.rear.finsHeight; + C1 = rocket.rear.finsRootChord; + C2 = rocket.rear.finsFreeChord; + + Lcent = rocket.lengthCenter; + Lnos = rocket.parafoil.noseLength; + + Xle1 = Lcent + Lnos - rocket.rear.finsAxialDistance - C1; + + Daft = rocket.rear.boatFinalDiameter; + Laft = rocket.rear.boatLength; + + xNos = Lnos - Lnos*cos(linspace(0, pi/2, 50)); + if strcmp(rocket.parafoil.noseType, 'KARMAN') + theta = @(x) acos( 1 - ( (2*x)./Lnos ) ); + Karman = @(x) ( r/sqrt(pi) ) * sqrt( theta(x) - ( sin(2*theta(x))./ 2 ) ); + yNos = Karman(xNos); + elseif strcmp(rocket.parafoil.noseType, 'HAACK') + theta = @(x) acos( 1 - ( (2*x)./Lnos ) ); + Haack = @(x) ( r/sqrt(pi) ) * sqrt( theta(x) - ( sin(2*theta(x))./ 2 ) + (1/3)*sin(theta(x)).^3 ); + yNos = Haack(xNos); + elseif strcmp(rocket.parafoil.noseType, 'OGIVE') + rho = (r^2 + Lnos^2)/(2*r); + Ogive = @(x) sqrt(rho^2 - (Lnos - x).^2) + r - rho; + yNos = Ogive(xNos); + elseif strcmp(rocket.parafoil.noseType, 'POWER') + power = rocket.parafoil.nosePower; + Power = @(x) r * (x/Lnos).^(power); + yNos = Power(xNos); + elseif strcmp(rocket.parafoil.noseType, 'MHAACK') + p = rocket.parafoil.nosePMod; + c = rocket.parafoil.noseCMod; + xMod = @(x, p) (x/Lnos).^(p)*Lnos; + thetaMod = @(x, p) acos( 1 - ( (2*xMod(x, p))./Lnos ) ); + haackSeriesMod = @(x, p, C) ( r/sqrt(pi) ) * sqrt( thetaMod(x, p) ... + - ( sin(2*thetaMod(x, p))./ 2 ) + C*sin(thetaMod(x, p)).^3 ); + yNos = haackSeriesMod(xNos, p, c); + end + + if strcmp(rocket.rear.boatType, 'OGIVE') % [-] Boat-tail shape. 0: Cone, 1: Tangent Ogive + [xBoat, yBoat] = computeTangentBoatPoints(2*r, Daft, Laft); + else + xBoat = [0 Laft]; + yBoat = [r Daft/2]; + end + + %%% figure begin + roc = figure(); + hold on + + %%% NOSECONE + plot(xNos, yNos, 'k'); + plot(xNos, -yNos, 'k'); + plot([Lnos Lnos], [-r r], 'k'); + + %%% CENTERBODY + plot([Lnos Lnos+Lcent], [r r], 'k'); + plot([Lnos Lnos+Lcent], [-r -r], 'k'); + plot([Lnos+Lcent Lnos+Lcent], [-r r], 'k'); + + %%% BOAT-TAIL PLOT + plot(xBoat+Lnos+Lcent, yBoat, 'k'); + plot(xBoat+Lnos+Lcent, -yBoat, 'k'); + plot([Lnos+Lcent+Laft Lnos+Lcent+Laft], [-Daft/2 Daft/2], 'k'); + + %%% FINS PLOT + % top + plot([Xle1 Xle1+deltaXLE], [r r+height],'k'); + plot([Xle1+C1 Xle1+deltaXLE+C2], [r r+height],'k'); + plot([Xle1+deltaXLE Xle1+deltaXLE+C2], [r+height r+height],'k'); + plot([Xle1 Xle1+C1], [r r], 'k'); + % bottom + plot([Xle1 Xle1+deltaXLE], [-r -r-height],'k'); + plot([Xle1+C1 Xle1+deltaXLE+C2], [-r -r-height],'k'); + plot([Xle1+deltaXLE Xle1+deltaXLE+C2], [-r-height, -r-height],'k'); + plot([Xle1 Xle1+C1], [-r -r], 'k'); + + % plot([Xle1 Xle1+deltaXLE], [r+height r+height], 'k--') + % plot([Xle1+deltaXLE Xle1+deltaXLE], [r+height r],'k--') + + %%% BAYS + lengths = rocket.absolutePositions.values + 2*Lnos; + bays = rocket.absolutePositions.keys; + xline(0,'r-.', 'Label', 'NOSE', ... + 'LabelOrientation', 'aligned', 'LabelVerticalAlignment', 'bottom', ... + 'LabelHorizontalAlignment', 'right'); + for i = 1:length(lengths) + xline(lengths(i), '--', 'Label', bays(i), ... + 'LabelOrientation', 'aligned', 'LabelVerticalAlignment', 'bottom', ... + 'LabelHorizontalAlignment', 'right'); + end + boatPlotLength = rocket.length - rocket.rear.boatLength; + xline(boatPlotLength,'r-.', 'Label', 'BOAT-TAIL', ... + 'LabelOrientation', 'aligned', 'LabelVerticalAlignment', 'bottom', ... + 'LabelHorizontalAlignment', 'right'); + + axis equal + % set(gca, 'xlim', [-100, Lnos+Lcent+Laft+100]); + + %%% TITLE + title(string(strrep(mission.name, '_', ' '))); +end -- GitLab