import math


def create_arrowhead(A, B):
    """
    Use trigonometry to calculate the arrowheads vertex positions according to the edge direction.

    Parameters
    ----------
    A : array
        x,y Starting point of edge
    B : array
        x,y Ending point of edge

    Returns
    -------
    B, v1, v2 : tuple
        The point of head, the v1 xy and v2 xy points of the two base vertices of the arrowhead.
    """
    w = 0.003 # Half of the triangle base width
    h = w / 0.26794919243 # tan(15)

    AB = [B[0] - A[0], B[1] - A[1]]
    mag = math.sqrt(AB[0]**2.0 + AB[1]**2.0)
    if mag == 0:
        mag = 1.0
    d = 0.012 # Distance from node

    u0 = AB[0] / mag
    u1 = AB[1] / mag
    U = [u0, u1] # Unit vector of AB

    V = [-U[1], U[0]] # Unit vector perpendicular to AB

    C = [ B[0] - d * u0, B[1] - d * u1 ]

    v1 = [C[0] - h * U[0] + w * V[0], C[1] - h * U[1] + w * V[1]]
    v2 = [C[0] - h * U[0] - w * V[0], C[1] - h * U[1] - w * V[1]]

    return (C, v1, v2)