  Despite being a fundamental property of galaxies that dictates the form of
the potential, the 3D shape is intrinsically difficult to determine from
observations. The improving quality of triaxial modeling methods in recent
years has made it possible to measure these shapes more accurately. This study
provides a comprehensive understanding of the stellar and dark matter (DM)
shapes of galaxies and the connections between them as well as with other
galaxy properties. Using the hydrodynamical cosmological simulation Magneticum
Box4, we computed the stellar and DM shapes of galaxies at different radii. We
determined their morphologies, their projected morphological and kinematic
parameters, and their fractions of in-situ formed stars. The DM follows the
stellar component in shape and orientation at $3R_{1/2}$, indicating that DM is
heavily influenced by the baryonic potential in the inner parts of the halo.
The outer DM halo is independent of the inner properties such as morphology,
however, and is more closely related to the large-scale anisotropy of the gas
inflow. The stellar shapes of galaxies are correlated with morphology:
ellipticals feature more spherical and prolate shapes than disk galaxies.
Galaxies with more rotational support are flatter, and the stellar shapes are
connected to the mass distribution. In particular, more extended elliptical
galaxies have larger triaxialities. Finally, the shapes can be used to
constrain the in-situ fraction of stars when combined with the stellar mass.
The found relations show that shapes depend on the details of the accretion
history. The similarities between the inner DM and stellar shapes signal the
importance of baryonic matter for DM in galaxies and will help improve
dynamical models in the future. At large radii the DM shape is completely
decoupled from the central galaxy and is coupled more to the large-scale
inflow.
