canonically_rotate_circles#
- canonically_rotate_circles(circles, degree=0)#
Rotate a system of circles to a canonical orientation via PCA.
Given a mapping where values are
Circle
instances, compute the PCA of their centers (weighted by radius for the mass center), translate to the center of mass, align with the first principal component, optionally rotate bydegree
(degrees), and (if needed) flip so more mass lies to the right (positive real axis).If
degree = 0
, the primary axis aligns horizontally (i.e., circles are visually “laid out” left–right).- Parameters:
circles (dict) – A dict whose values are
Circle
objects.degree (int) – Additional rotation in degrees applied after PCA alignment.
- Returns:
dict – A new dict with the same keys, where each value is a rotated
Circle
(centers transformed; radii preserved).- Raises:
ValueError – If any value in
circles
is not aCircle
.- Return type:
dict