def calc_perpendicular_distance(N, ref_dirs):
    """Calculate perpendicular distance from points to reference directions."""
    u = np.tile(ref_dirs, (len(N), 1))
    v = np.repeat(N, len(ref_dirs), axis=0)

    norm_u = np.linalg.norm(u, axis=1)

    scalar_proj = np.sum(v * u, axis=1) / norm_u
    proj = scalar_proj[:, None] * u / norm_u[:, None]
    val = np.linalg.norm(proj - v, axis=1)
    matrix = np.reshape(val, (len(N), len(ref_dirs)))

    return matrix
Calculate perpendicular distance from points to reference directions.
pymoo/functions/standard/calc_perpendicular_distance.py