import math


def pip_wn(point, pgon):
    """
    Determines whether a point is in a polygon using the 
    winding number algorithm using trigonometric functions. 
    Code adopted from the C program in Graphics Gems IV
    (Haines 1994).
    Input
      point: the point
      pgon: a list of points as the vertices for a polygon
    Ouput
      Returns a boolean value of True or False and the number
      of times the half line crosses the polygon boundary
    """
    if pgon[0] != pgon[-1]:
        pgon.append(pgon[0])
    n = len(pgon)
    xp = point.x
    yp = point.y
    wn = 0
    for i in range(n-1):
        xi = pgon[i].x
        yi = pgon[i].y
        xi1 = pgon[i+1].x
        yi1 = pgon[i+1].y
        thi = (xp-xi)*(xp-xi1) + (yp-yi)*(yp-yi1)
        norm = (math.sqrt((xp-xi)**2+(yp-yi)**2) 
                * math.sqrt((xp-xi1)**2+(yp-yi1)**2))
        if thi != 0:
            thi = thi/norm
        thi = math.acos(thi)
        wn += thi
    wn /= 2*math.pi
    wn = int(wn)
    return wn is not 0, wn