DBM Python Code

The code for calculating DBM in python is:

import math
import numpy as np
from pyhull.convex_hull import ConvexHull
from pyhull import qconvex
def   calcDBM(points,nsides=4, mu=0.8, initang=0):
    ang = 2*math.pi/nsides
    initang = initang +ang/2

    points = np.matrix(points)
    npoints = points.shape[0]
    P=np.matrix([ [ mu*math.cos(ang*i+initang),
                    mu*math.sin(ang*i+initang),
                    points[j,1],
                    -points[j,0],
                    -points[j,1]*mu*math.cos(ang*i+initang)+points[j,0]*mu*math.sin(ang*i+initang)]
                                        for j in range(0, npoints )  for i in range(0,nsides)])

    hull = qconvex('n', P.tolist())
    cols = hull.pop(0)
    rows =int(hull.pop(0))

    matrica = np.matrix([ np.fromstring(hull.pop(0), sep=' ') for i in range(0,rows)])
    absvalue=np.absolute(matrica[:,5])
    sel = np.array(absvalue>0)
    sel = sel[:,0]
    absvalue = absvalue[sel]

    matrica = matrica[sel,:]

    DBM =-np.vstack((np.matrix([0,0,-1,0,0,0]),
        np.column_stack(( np.divide(matrica[:,0], absvalue),
                            np.divide(matrica[:,1], absvalue),
                            np.divide(matrica[:,5], absvalue),
                            np.divide(matrica[:,2], absvalue),
                            np.divide(matrica[:,3], absvalue),
                            np.divide(matrica[:,4], absvalue)))))

    return DBM