Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • skyward/matlab-dependencies/common
1 result
Select Git revision
Show changes
Commits on Source (5)
...@@ -422,18 +422,25 @@ classdef Rocket < Component ...@@ -422,18 +422,25 @@ classdef Rocket < Component
%%% FINS PLOT %%% FINS PLOT
% top % top
plot([Xle1 Xle1+deltaXLE], [r r+height],'k'); plot([Xle1 Xle1+deltaXLE], [r r+height],'k'); % center side line
plot([Xle1+C1 Xle1+deltaXLE+C2], [r r+height],'k'); plot([Xle1+C1 Xle1+deltaXLE+C2], [r r+height],'k'); % boat side line
plot([Xle1+deltaXLE Xle1+deltaXLE+C2], [r+height r+height],'k'); plot([Xle1+deltaXLE Xle1+deltaXLE+C2], [r+height r+height],'k'); % upper
plot([Xle1 Xle1+C1], [r r], 'k');
% bottom % bottom
plot([Xle1 Xle1+deltaXLE], [-r -r-height],'k'); plot([Xle1 Xle1+deltaXLE], [-r -r-height],'k');
plot([Xle1+C1 Xle1+deltaXLE+C2], [-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+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--') if strcmp(obj.rear.boatType, 'OGIVE')
% plot([Xle1+deltaXLE Xle1+deltaXLE], [r+height r],'k--') xBoat_new = xBoat +Lnos+Lcent;
[idx, xFine, yFine, ~, ~] = computeInnestedFins(r, height, Xle1, deltaXLE, C1, C2, xBoat_new, yBoat);
plot(xFine(1:idx),yFine(1:idx),'k')
plot(xFine(1:idx),-yFine(1:idx),'k')
plot([Xle1 Xle1+C1], [r r], ':k'); % lower edge fin up
plot([Xle1 Xle1+C1], [-r -r], ':k'); % lower edge fin down
else
plot([Xle1 Xle1+C1], [r r], 'k'); % lower edge fin up
plot([Xle1 Xle1+C1], [-r -r], 'k'); % lower edge fin down
end
%%% BAYS %%% BAYS
lengths = obj.absolutePositions.values + 2*Lnos; lengths = obj.absolutePositions.values + 2*Lnos;
...@@ -442,7 +449,8 @@ classdef Rocket < Component ...@@ -442,7 +449,8 @@ classdef Rocket < Component
xline(0,'r-.', 'Label', 'NOSE', ... xline(0,'r-.', 'Label', 'NOSE', ...
'LabelOrientation', 'aligned', 'LabelVerticalAlignment', 'bottom', ... 'LabelOrientation', 'aligned', 'LabelVerticalAlignment', 'bottom', ...
'LabelHorizontalAlignment', 'right'); 'LabelHorizontalAlignment', 'right');
for i = 1:length(lengths) [lPos, ~] = size(lengths);
for i = 1:lPos
if i == iMotor if i == iMotor
line([lengths(i) lengths(i)], [-1 1], 'LineStyle', '--', 'Color', 'b'); % Draw the line line([lengths(i) lengths(i)], [-1 1], 'LineStyle', '--', 'Color', 'b'); % Draw the line
text(lengths(i), -1 + 0.3, baysBody(i), 'VerticalAlignment', 'top', ... text(lengths(i), -1 + 0.3, baysBody(i), 'VerticalAlignment', 'top', ...
......
function [idx, xFine, yFine, xInt, yInt] = computeInnestedFins(d, height, Xle1, deltaXLE, C1, C2, xBoat_new, yBoat)
%{
computeInnestedFins - function used to plot fins innested in boat
INPUTS:
- d, double, rocket diameter
- height, double, fins height
- Xle1, double, ogive-to-free chord distance
- deltaXLE, double, difference between ogive-to-free chord and
ogive-to-attached chord
- C1, double, free chord
- C2, double, attached chord
- xBoat, double [1, nPoints], boat tail plot x-coordinates
- yBoat, double [1, nPoints], boat tail plot y-coordinates
OUTPUTS:
- idx, double, index of intersection between fins and boat
- xFine, [1, nPoints], refined x data
- yFine, [1, nPoints], refined y data
- xInt, double, intersection x data
- yInt, double, intersection y data
CALLED FUNCTIONS: /
VERSIONS: #0, release, Giulia Ghirardini
%}
% Small preliminary config
nPoints = 1000;
extension = 1.2;
% Find angular coefficient of the trapezium edge near boat
m = ((d+height)-d) / ((Xle1+deltaXLE+C2) - (Xle1+C1));
% Entend the line
pt1 = [Xle1+C1 d];
pt2 = [Xle1+deltaXLE+C2 d+height];
pext = pt1 + (pt1-pt2)*extension;
xext = linspace(Xle1+deltaXLE+C2,pext(1),100);
yext = d+height + m*(xext - (Xle1+deltaXLE+C2));
% Define a common x-domain for interpolation
xFine = linspace(max(min(xBoat_new), min(xext)), min(max(xBoat_new), max(xext)), nPoints);
% Interpolate yBoat and yext to the common x-domain
yBoat_interp = interp1(xBoat_new, yBoat, xFine, 'linear');
yext_interp = interp1(xext, yext, xFine, 'linear');
% Compute the absolute difference in y-values
dy = abs(yBoat_interp - yext_interp);
% Find the index of the minimum difference
[~, idx] = min(dy);
% Retrieve the x and y coordinates at this index
xInt = xFine(idx);
yInt = yBoat_interp(idx); % or yext_interp(minIdx), as they are nearly equal
yFine = yext_interp;
end
\ No newline at end of file
...@@ -19,7 +19,7 @@ rRocket = dRocket/2; ...@@ -19,7 +19,7 @@ rRocket = dRocket/2;
eqRadius = abs(dAft/2 - rRocket); eqRadius = abs(dAft/2 - rRocket);
rho = (lAft^2 + eqRadius^2) / (2*eqRadius); rho = (lAft^2 + eqRadius^2) / (2*eqRadius);
nPoints = 20; nPoints = 100;
xBoat = lAft * linspace(0, 1, nPoints); xBoat = lAft * linspace(0, 1, nPoints);
yBoat = sqrt(rho^2 - xBoat.^2) - (rho - rRocket); yBoat = sqrt(rho^2 - xBoat.^2) - (rho - rRocket);
end end
\ No newline at end of file
...@@ -140,6 +140,15 @@ switch flag ...@@ -140,6 +140,15 @@ switch flag
set(plotFin2n,'Tag','gaplotFin2n'); set(plotFin2n,'Tag','gaplotFin2n');
plotFin3n = plot([Xle1+deltaXLE Xle1+deltaXLE+C2], [-r-H, -r-H],'k'); plotFin3n = plot([Xle1+deltaXLE Xle1+deltaXLE+C2], [-r-H, -r-H],'k');
set(plotFin3n,'Tag','gaplotFin3n'); set(plotFin3n,'Tag','gaplotFin3n');
if strcmp(rocket.rear.boatType, 'OGIVE')
xBoat_new = xBoat +Lnos+Lcent;
[idx, xFine, yFine, ~, ~] = computeInnestedFins(r, H, Xle1, deltaXLE, C1, C2, xBoat_new, yBoat);
plot(xFine(1:idx),yFine(1:idx),'k')
plot(xFine(1:idx),-yFine(1:idx),'k')
else
plot([Xle1 Xle1+C1], [r r], 'k'); % lower edge fin up
plot([Xle1 Xle1+C1], [-r -r], 'k'); % lower edge fin down
end
set(gca, 'xlim', [-100, Lnos+Lcent+Laft+100]); set(gca, 'xlim', [-100, Lnos+Lcent+Laft+100]);
axis equal axis equal
xlabel('x [mm]'); ylabel('y [mm]'); title('Current Best Shape') xlabel('x [mm]'); ylabel('y [mm]'); title('Current Best Shape')
......
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');
% 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
% 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') && ~isprop(ch2(i), 'Label') % Check if the child has a 'Color' property
set(ch2(i), 'Color', 'blue', 'LineStyle', '--', 'LineWidth', 1.2); % Set color to blue, dashed line
end
end
copyobj(ch2, merged_ax); % Copy to merged axes
% Set up legend with correct colors
legend_labels = [ch1(9), ch2(end)]; % 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, 'Length [m]');
title('Rocket Comparison');
axis equal
disp('Figures merged successfully.');
clear
clc
mission = Mission('design');
rocket = Rocket(mission);
gpx = rocket.rocketPlot(mission);
\ No newline at end of file
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