This algorithm is based on [this answer][1], is written in Python, and assumes you want to align an edge with the X axis (horizontal axis). If you want to align it with the Y axis, replace the `xVec` in the code below with an `yVec = [0,1]`.

<!-- language: lang-python -->

    from math import degrees, sqrt, acos
    
    def dotproduct(v1, v2):
      return sum( (a*b) for a, b in zip(v1, v2) )
    
    def length(v):
      return sqrt( dotproduct(v, v) )
    
    def angle(v1, v2):
      return acos( dotproduct(v1, v2) / ( length(v1) * length(v2) ) )
      
    def vec_subtraction( v1, v2 ):
        return [ a - b for a, b in zip( v1, v2 ) ]
    
    def calc_edge_vec(  poly, edge ):
        p1 = poly['points'][ edge[0] ]
        p2 = poly['points'][ edge[1] ]
        
        return vec_subtraction( p2, p1 )
    
    p = {
    	'points' : [ (0,0), (3,5), (7,2), (1,4) ],
    	'edges'  : [ (0,3), (3,1), (1,2), (2,0) ]
    }
    
    xVec = [1,0] # Horizontal X axis vector - to align with
    
    for e in p['edges']:
        edgeVec = calc_edge_vec( p, e )
        a       = angle( edgeVec, xVec )
        print( degrees(a) )

<!-- language: lang-python -->    
    
  [1]: http://stackoverflow.com/questions/2827393/angles-between-two-n-dimensional-vectors-in-python