Components Class#

class rocketpy.Components[source]#

A Collection Class to hold components of the Rocket class. Each component is an object that is added to the rocket at a specific position relative to the rocket’s coordinate system origin. Components can be added to the rocket using the ‘add’ methods. This class is currently used specifically for holding aerodynamic surfaces.

Variables:
  • _components (list of namedtuple) – A list of named tuples representing all the components and their positions relative to the rocket.

  • component_tuple (namedtuple) – A named tuple representing a component and its position within the rocket.

__init__()[source]#

Initialize an empty components list instance.

__repr__()[source]#

Return a string representation of the Components instance.

__len__()[source]#

Return the number of components in the list of components.

__getitem__(index)[source]#

Return the component at the specified index in the list of components.

__iter__()[source]#

Return an iterator over the list of components.

add(component, position)[source]#

Add a component to the list of components.

Parameters:
  • component (Any) – The component to be added to the rocket.

  • position (int, float) – The position of the component relative to the rocket’s coordinate system origin.

Return type:

None

get_by_type(component_type)[source]#

Search the list of components and return a list with all the components of the given type.

Parameters:

component_type (type) – The type of component to be returned.

Returns:

A list of components matching the specified type.

Return type:

list

get_tuple_by_type(component_type)[source]#

Search the list of components and return a list with all the components of the given type.

Parameters:

component_type (type) – The type of component to be returned.

Returns:

A list of components matching the specified type.

Return type:

list

get_positions()[source]#

Return a list of all the positions of the components in the list of components.

Returns:

A list of all the positions of the components in the list of components.

Return type:

list

remove(component)[source]#

Remove a component from the list of components. If more than one instance of the same component is present in the list, only the first instance is removed.

Parameters:

component (Any) – The component to be removed from the rocket.

Return type:

None

pop(index=-1)[source]#

Pop a component from the list of components.

Parameters:

index (int) – The index of the component to be removed from the list of components. If no index is specified, the last component is removed.

Returns:

component – The component removed from the list of components.

Return type:

Any

clear()[source]#

Clear all components from the list of components.

Return type:

None

sort_by_position(reverse=False)[source]#

Sort the list of components by position.

Parameters:

reverse (bool) – If True, sort in descending order. If False, sort in ascending order.

Return type:

None