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
ofnamedtuple
) – 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.
- 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_components()[source]#
Return a list of all the components in the list of components.
- Returns:
A list of all the components in the list of components.
- Return type:
list[Component]
- 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