def project_and_align_z_with_x(polygons, z_direction):
    """
    Rotate polygons so that the Z-direction is aligned with the X-axis in 2D.

    Parameters:
    polygons (list[Polygon]): List of Shapely Polygons representing the projected 2D polygons.
    z_direction (np.array): The 2D direction vector where the Z-axis is projected.

    Returns:
    list[Polygon]: Rotated polygons with the Z-direction aligned with the X-axis.
    """
    # Calculate the angle between the Z-direction projection and the X-axis
    angle_rad = np.arctan2(z_direction[1], z_direction[0])
    angle_deg = np.degrees(angle_rad)

    # Rotate polygons to align Z-direction with X-axis
    rotated_polygons = [
        rotate(polygon, angle_deg, origin=(0, 0), use_radians=False)
        for polygon in polygons
    ]

    return rotated_polygons

    Rotate polygons so that the Z-direction is aligned with the X-axis in 2D.

    Parameters:
    polygons (list[Polygon]): List of Shapely Polygons representing the projected 2D polygons.
    z_direction (np.array): The 2D direction vector where the Z-axis is projected.

    Returns:
    list[Polygon]: Rotated polygons with the Z-direction aligned with the X-axis.
    
infinigen/core/constraints/example_solver/geometry/stability.py