Esempio n. 1
0
def center_of_mass_polyline_xy_numba(polyline):
    """ Compute the center of mass of polyline edges in the XY plane, defined as an array of points.

    Parameters
    ----------
    polyline : array
        XY(Z) coordinates representing the corners of a polyline (m x 3).

    Returns
    -------
    array
        The XY(Z) coordinates of the center of mass.

    """

    L = 0
    cx = 0
    cy = 0
    m = polyline.shape[0]
    ii = list(range(1, m)) + [0]
    for i in range(m):
        p1 = polyline[i, :]
        p2 = polyline[ii[i], :]
        d = length_vector_xy_numba(subtract_vectors_xy_numba(p2, p1))
        cx += 0.5 * d * (p1[0] + p2[0])
        cy += 0.5 * d * (p1[1] + p2[1])
        L += d
    c = array([cx, cy, 0.])
    sc = 1. / L
    return scale_vector_numba(c, factor=sc)
Esempio n. 2
0
def midpoint_point_point_numba(u, v):
    """Compute the midpoint of two points.

    Parameters
    ----------
    u : array
        XYZ coordinates of the first point.
    v : array
        XYZ coordinates of the second point.

    Returns
    -------
    array
        XYZ coordinates of the midpoint.
    """
    return scale_vector_numba(add_vectors_numba(u, v), factor=0.5)
Esempio n. 3
0
def centroid_points_numba(u):
    """Compute the centroid of a set of points.

    Parameters
    ----------
    u : array
        An array of XYZ coordinates.

    Returns
    -------
    array
        Centroid of the points.
    """
    m = u.shape[0]
    sc = 1. / m
    return scale_vector_numba(sum_vectors_numba(u, axis=0), factor=sc)