diff --git a/CHANGELOG.md b/CHANGELOG.md index 09e2b4b7d..0d168763a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Attention: The newest changes should be on top --> ### Fixed +- BUG: do not allow drawing rockets with no aerodynamic surface [#774](https://github.com/RocketPy-Team/RocketPy/pull/774) - BUG: update flight simulation logic to include burn start time [#778](https://github.com/RocketPy-Team/RocketPy/pull/778) ## [v1.8.0] - 2025-01-20 diff --git a/rocketpy/plots/rocket_plots.py b/rocketpy/plots/rocket_plots.py index 4521e5793..db53f6f49 100644 --- a/rocketpy/plots/rocket_plots.py +++ b/rocketpy/plots/rocket_plots.py @@ -212,6 +212,9 @@ def draw(self, vis_args=None, plane="xz", *, filename=None): eps, jpg, jpeg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff and webp (these are the formats supported by matplotlib). """ + + self.__validate_aerodynamic_surfaces() + if vis_args is None: vis_args = { "background": "#EEEEEE", @@ -248,6 +251,12 @@ def draw(self, vis_args=None, plane="xz", *, filename=None): plt.tight_layout() show_or_save_plot(filename) + def __validate_aerodynamic_surfaces(self): + if not self.rocket.aerodynamic_surfaces: + raise ValueError( + "The rocket must have at least one aerodynamic surface to be drawn." + ) + def _draw_aerodynamic_surfaces(self, ax, vis_args, plane): """Draws the aerodynamic surfaces and saves the position of the points of interest for the tubes.""" @@ -399,6 +408,8 @@ def _draw_generic_surface( def _draw_tubes(self, ax, drawn_surfaces, vis_args): """Draws the tubes between the aerodynamic surfaces.""" + radius = 0 + last_x = 0 for i, d_surface in enumerate(drawn_surfaces): # Draw the tubes, from the end of the first surface to the beginning # of the next surface, with the radius of the rocket at that point @@ -670,9 +681,10 @@ def all(self): """ # Rocket draw - print("\nRocket Draw") - print("-" * 40) - self.draw() + if len(self.rocket.aerodynamic_surfaces) > 0: + print("\nRocket Draw") + print("-" * 40) + self.draw() # Mass Plots print("\nMass Plots")