@@ -190,9 +190,8 @@ function RocketPlotter(app)
190190 plot(app .UIAxes , [x(end ),x(end )], [dia / 2 ,-dia / 2 ], app .lineColor )
191191
192192
193- % plot the fins of the rocket
193+ % plot the components of the rocket
194194 app .PlotFins()
195-
196195 app .PlotComponents();
197196
198197 % define the standard limits for the plot
@@ -440,173 +439,169 @@ function PlotComponents(app)
440439
441440 % get the components from the rocket
442441
443- if ~isempty(app .rocket )
444- compList = app .rocket .ComponentList ;
442+ compList = app .rocket .ComponentList ;
445443
446- % in the event that the rocket has components:
447- if numEntries(compList ) > 0
448- len = numEntries(compList );
449- values = compList .values ;
444+ % in the event that the rocket has components:
445+ if numEntries(compList ) > 0
446+ len = numEntries(compList );
447+ values = compList .values ;
450448
451- % go through each and check for fins
452- for idx = 1 : len
453- % first case is a tank
454- if isa(values{idx }, ' Tank' )
449+ % go through each and check for fins
450+ for idx = 1 : len
451+ % first case is a tank
452+ if isa(values{idx }, ' Tank' )
455453
456- tankObj = values{idx };
454+ tankObj = values{idx };
455+
456+ leng = tankObj .Length ;
457+ rad = tankObj .TankDia / 2 ;
458+ FuelOx = tankObj .FuelOx ;
459+ dist = tankObj .Position(1 );
460+ if strcmp(FuelOx , ' Fuel' )
461+ color = ' r' ;
462+ else
463+ color = ' b' ;
464+ end
457465
458- leng = tankObj .Length ;
459- rad = tankObj .TankDia / 2 ;
460- FuelOx = tankObj .FuelOx ;
461- dist = tankObj .Position(1 );
462- if strcmp(FuelOx , ' Fuel' )
463- color = ' r' ;
466+ if app .ThreeDPlot
467+
468+ isSpherica = false ;
469+ if isSpherica
470+ [Z , Y , X ] = cylinder(rad ,100 ); % make unit cyliner along x axis
471+ X_body = X *(leng - 2 * rad )+dist + rad ;
472+ surf(app .UIAxes , X_body ,Y ,Z , " FaceColor" ,color ,' FaceAlpha' , 0.7 , ' EdgeAlpha' ,0 );
473+
474+ x_res_nose = 0 : rad / 50 : rad ;
475+ nose_radius_func_ish = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - rad ).^2 )./(rad ^ 2 ));
476+ [Z , Y , X ] = cylinder(nose_radius_func_ish , 100 );
477+ X_nose = X * rad + dist ;
478+ surf(app .UIAxes , X_nose ,Y ,Z , " FaceColor" ,color ,' FaceAlpha' , 0.7 , ' EdgeAlpha' ,0 );
479+
480+ x_res_nose = rad : rad / 50 : 2 * rad ;
481+ nose_radius_func_ish = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - rad ).^2 )./(rad ^ 2 ));
482+ [Z , Y , X ] = cylinder(nose_radius_func_ish , 100 );
483+ X_nose = X * rad + dist + leng - rad ;
484+ surf(app .UIAxes , X_nose ,Y ,Z , " FaceColor" ,color ,' FaceAlpha' , 0.7 , ' EdgeAlpha' ,0 );
464485 else
465- color = ' b' ;
486+ l_a = sqrt(2 )*rad ;
487+ [Z , Y , X ] = cylinder(rad ,100 ); % make unit cyliner along x axis
488+ X_body = X *(leng - 2 * l_a )+dist + l_a ;
489+ surf(app .UIAxes , X_body ,Y ,Z , " FaceColor" ,color ,' FaceAlpha' , 0.7 , ' EdgeAlpha' ,0 );
490+
491+ x_res_nose = 0 : l_a / 50 : l_a ;
492+ nose_radius_func_ish = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - l_a ).^2 )./(l_a ^ 2 ));
493+ [Z , Y , X ] = cylinder(nose_radius_func_ish , 100 );
494+ X_nose = X * l_a + dist ;
495+ surf(app .UIAxes , X_nose ,Y ,Z , " FaceColor" ,color ,' FaceAlpha' , 0.7 , ' EdgeAlpha' ,0 );
496+
497+ x_res_nose = l_a : l_a / 50 : 2 * l_a ;
498+ nose_radius_func_ish = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - l_a ).^2 )./(l_a ^ 2 ));
499+ [Z , Y , X ] = cylinder(nose_radius_func_ish , 100 );
500+ X_nose = X * l_a + dist + leng - l_a ;
501+ surf(app .UIAxes , X_nose ,Y ,Z , " FaceColor" ,color ,' FaceAlpha' , 0.7 , ' EdgeAlpha' ,0 );
466502 end
467503
468- if app .ThreeDPlot
469-
470- isSpherica = false ;
471- if isSpherica
472- [Z , Y , X ] = cylinder(rad ,100 ); % make unit cyliner along x axis
473- X_body = X *(leng - 2 * rad )+dist + rad ;
474- surf(app .UIAxes , X_body ,Y ,Z , " FaceColor" ,color ,' FaceAlpha' , 0.7 , ' EdgeAlpha' ,0 );
475-
476- x_res_nose = 0 : rad / 50 : rad ;
477- nose_radius_func_ish = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - rad ).^2 )./(rad ^ 2 ));
478- [Z , Y , X ] = cylinder(nose_radius_func_ish , 100 );
479- X_nose = X * rad + dist ;
480- surf(app .UIAxes , X_nose ,Y ,Z , " FaceColor" ,color ,' FaceAlpha' , 0.7 , ' EdgeAlpha' ,0 );
481-
482- x_res_nose = rad : rad / 50 : 2 * rad ;
483- nose_radius_func_ish = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - rad ).^2 )./(rad ^ 2 ));
484- [Z , Y , X ] = cylinder(nose_radius_func_ish , 100 );
485- X_nose = X * rad + dist + leng - rad ;
486- surf(app .UIAxes , X_nose ,Y ,Z , " FaceColor" ,color ,' FaceAlpha' , 0.7 , ' EdgeAlpha' ,0 );
487- else
488- l_a = sqrt(2 )*rad ;
489- [Z , Y , X ] = cylinder(rad ,100 ); % make unit cyliner along x axis
490- X_body = X *(leng - 2 * l_a )+dist + l_a ;
491- surf(app .UIAxes , X_body ,Y ,Z , " FaceColor" ,color ,' FaceAlpha' , 0.7 , ' EdgeAlpha' ,0 );
492-
493- x_res_nose = 0 : l_a / 50 : l_a ;
494- nose_radius_func_ish = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - l_a ).^2 )./(l_a ^ 2 ));
495- [Z , Y , X ] = cylinder(nose_radius_func_ish , 100 );
496- X_nose = X * l_a + dist ;
497- surf(app .UIAxes , X_nose ,Y ,Z , " FaceColor" ,color ,' FaceAlpha' , 0.7 , ' EdgeAlpha' ,0 );
498-
499- x_res_nose = l_a : l_a / 50 : 2 * l_a ;
500- nose_radius_func_ish = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - l_a ).^2 )./(l_a ^ 2 ));
501- [Z , Y , X ] = cylinder(nose_radius_func_ish , 100 );
502- X_nose = X * l_a + dist + leng - l_a ;
503- surf(app .UIAxes , X_nose ,Y ,Z , " FaceColor" ,color ,' FaceAlpha' , 0.7 , ' EdgeAlpha' ,0 );
504- end
505-
506- else % 2d plot
507- isSpehical = false ;
508- if isSpehical
509- xTank = [dist + l_a , dist + leng - l_a ];
510- yTank = [rad , rad ];
511- plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
512- xTank = [dist + l_a , dist + leng - l_a ];
513- yTank = [-rad , - rad ];
514- plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
515-
516- x_res_nose = 0 : rad / 50 : rad ;
517- yTank = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - rad ).^2 )./(rad ^ 2 ));
518- xTank = x_res_nose + dist ;
519- plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
520- plot(app .UIAxes , xTank , - 1 * yTank , ' LineStyle' ,' -' , ' Color' , color )
521-
522- x_res_nose = rad : rad / 50 : 2 * rad ;
523- yTank = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - rad ).^2 )./(rad ^ 2 ));
524- xTank = x_res_nose + dist + leng - 2 * rad ;
525- plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
526- plot(app .UIAxes , xTank , - 1 * yTank , ' LineStyle' ,' -' , ' Color' , color )
527- else
528- l_a = sqrt(2 )*rad ;
529- xTank = [dist + l_a , dist + leng - l_a ];
530- yTank = [rad , rad ];
531- plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
532- xTank = [dist + l_a , dist + leng - l_a ];
533- yTank = [-rad , - rad ];
534- plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
535-
536- x_res_nose = 0 : l_a / 50 : l_a ;
537- yTank = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - l_a ).^2 )./(l_a ^ 2 ));
538- xTank = x_res_nose + dist ;
539- plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
540- plot(app .UIAxes , xTank , - 1 * yTank , ' LineStyle' ,' -' , ' Color' , color )
541-
542- x_res_nose = l_a : l_a / 50 : 2 * l_a ;
543- yTank = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - l_a ).^2 )./(l_a ^ 2 ));
544- xTank = x_res_nose + dist + leng - 2 * l_a ;
545- plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
546- plot(app .UIAxes , xTank , - 1 * yTank , ' LineStyle' ,' -' , ' Color' , color )
547- end
504+ else % 2d plot
505+ isSpehical = false ;
506+ if isSpehical
507+ xTank = [dist + l_a , dist + leng - l_a ];
508+ yTank = [rad , rad ];
509+ plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
510+ xTank = [dist + l_a , dist + leng - l_a ];
511+ yTank = [-rad , - rad ];
512+ plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
513+
514+ x_res_nose = 0 : rad / 50 : rad ;
515+ yTank = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - rad ).^2 )./(rad ^ 2 ));
516+ xTank = x_res_nose + dist ;
517+ plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
518+ plot(app .UIAxes , xTank , - 1 * yTank , ' LineStyle' ,' -' , ' Color' , color )
519+
520+ x_res_nose = rad : rad / 50 : 2 * rad ;
521+ yTank = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - rad ).^2 )./(rad ^ 2 ));
522+ xTank = x_res_nose + dist + leng - 2 * rad ;
523+ plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
524+ plot(app .UIAxes , xTank , - 1 * yTank , ' LineStyle' ,' -' , ' Color' , color )
525+ else
526+ l_a = sqrt(2 )*rad ;
527+ xTank = [dist + l_a , dist + leng - l_a ];
528+ yTank = [rad , rad ];
529+ plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
530+ xTank = [dist + l_a , dist + leng - l_a ];
531+ yTank = [-rad , - rad ];
532+ plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
533+
534+ x_res_nose = 0 : l_a / 50 : l_a ;
535+ yTank = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - l_a ).^2 )./(l_a ^ 2 ));
536+ xTank = x_res_nose + dist ;
537+ plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
538+ plot(app .UIAxes , xTank , - 1 * yTank , ' LineStyle' ,' -' , ' Color' , color )
539+
540+ x_res_nose = l_a : l_a / 50 : 2 * l_a ;
541+ yTank = sqrt((rad ^ 2 ) -(rad ^ 2 ).*((x_res_nose - l_a ).^2 )./(l_a ^ 2 ));
542+ xTank = x_res_nose + dist + leng - 2 * l_a ;
543+ plot(app .UIAxes , xTank , yTank , ' LineStyle' ,' -' , ' Color' , color )
544+ plot(app .UIAxes , xTank , - 1 * yTank , ' LineStyle' ,' -' , ' Color' , color )
548545 end
546+ end
549547
550- elseif isa(values{idx }, ' PointMass' )
548+ elseif isa(values{idx }, ' PointMass' )
551549
552- ptObj = values{idx };
550+ ptObj = values{idx };
553551
554- xPos = ptObj .Position(1 );
555- yPos = ptObj .Position(2 );
556- zPos = ptObj .Position(3 );
557- color = ptObj .Color ;
552+ xPos = ptObj .Position(1 );
553+ yPos = ptObj .Position(2 );
554+ zPos = ptObj .Position(3 );
555+ color = ptObj .Color ;
558556
559557
560- if app .ThreeDPlot
561- plot3(app .UIAxes , xPos , yPos , zPos , ' .' , ' MarkerSize' , 30 , ' Color' , color )
562- else
563- plot(app .UIAxes , xPos , yPos , ' .' , MarkerSize = 30 , Color = color );
564- end
558+ if app .ThreeDPlot
559+ plot3(app .UIAxes , xPos , yPos , zPos , ' .' , ' MarkerSize' , 30 , ' Color' , color )
560+ else
561+ plot(app .UIAxes , xPos , yPos , ' .' , MarkerSize = 30 , Color = color );
562+ end
565563
566- elseif isa(values{idx }, ' PropulsionSystem' )
564+ elseif isa(values{idx }, ' PropulsionSystem' )
567565
568- propSys = values{idx };
566+ propSys = values{idx };
569567
570- dist = propSys .Position(1 );
571- dia = 2 * sqrt(propSys .ExitArea / pi );
572- color = propSys .Color ;
568+ dist = propSys .Position(1 );
569+ dia = 2 * sqrt(propSys .ExitArea / pi );
570+ color = propSys .Color ;
573571
574- % create the contour:
572+ % create the contour:
575573
576- xProp = linspace(0 ,3 * dia );
574+ xProp = linspace(0 ,3 * dia );
577575
578- yProp = .2 /.25 * (dia - 0.3 * dia * sin(1.5 * pi *(xProp -.06 )/(3 * dia )));
576+ yProp = .2 /.25 * (dia - 0.3 * dia * sin(1.5 * pi *(xProp -.06 )/(3 * dia )));
579577
580- xProp = xProp + dist ;
578+ xProp = xProp + dist ;
581579
582- endcapX = [xProp(end ), xProp(end )];
583- endcapY = [yProp(end ), - yProp(end )];
580+ endcapX = [xProp(end ), xProp(end )];
581+ endcapY = [yProp(end ), - yProp(end )];
584582
585- if app .ThreeDPlot
586- [Z , Y , X ] = cylinder(yProp , 100 );
583+ if app .ThreeDPlot
584+ [Z , Y , X ] = cylinder(yProp , 100 );
587585
588- X = X * 3 * dia + dist ;
586+ X = X * 3 * dia + dist ;
589587
590- plot3(app .UIAxes , X , Y , Z , ' LineStyle' ,' -' , ' Color' , color )
588+ plot3(app .UIAxes , X , Y , Z , ' LineStyle' ,' -' , ' Color' , color )
591589
592- else
593- plot(app .UIAxes , xProp ,yProp , " Color" , app .lineColor )
594- plot(app .UIAxes , xProp , - yProp , " Color" , app .lineColor )
595- plot(app .UIAxes , endcapX , endcapY , app .lineColor )
596- end
590+ else
591+ plot(app .UIAxes , xProp ,yProp , " Color" , app .lineColor )
592+ plot(app .UIAxes , xProp , - yProp , " Color" , app .lineColor )
593+ plot(app .UIAxes , endcapX , endcapY , app .lineColor )
594+ end
597595
598596
599597
600598
601599
602- end
603600 end
604601 end
605-
606- else
607- return
608602 end
609603
604+
610605 leng = numel(compList );
611606
612607 % for idx = 1:leng
@@ -758,6 +753,7 @@ function longitudeChanged(app, event)
758753
759754 % Button pushed function: AddComponentButton
760755 function AddComponent(app , event )
756+
761757 if isempty(app .rocket )
762758 uialert(app .UIFigure , ' No Rocket Object Found' , ' Please create or load a rocket first!' )
763759 return
@@ -875,10 +871,9 @@ function AeroDataButtonPushed(app, event)
875871 app.AeroLoc = src ;
876872 % Update UI text
877873 app.AeroDataButton.Text = file ;
878- % Update rocket if it exists
879- if ~isempty(app .rocket )
880- app.rocket.AeroData = src ;
881- end
874+ % Update rocket with AeroData
875+ app.rocket.AeroData = src ;
876+
882877 end
883878
884879 % Button pushed function: LoadRocketButton
@@ -975,6 +970,7 @@ function SaveRocketButtonPushed(app, event)
975970 app.rocket.NoseLength = app .NoseConeLengthmEditField .Value ;
976971 app.rocket.NoseGeometry = app .NoseConeGeometryDropDown .Value ;
977972 app.rocket.TotalMass = app .WetMasskgEditField .Value ;
973+ app.rocket.ComponentList = dictionary();
978974 rocketObj = app .rocket ;
979975 save(fullfile(pwd , matfilePath ), " rocketObj" )
980976 % update the tree node with the rocket object:
0 commit comments