Skip to content

wulff

perpendicular_vector(p, q, r)

a unit vector perpendicular to the triangle p q r

Source code in chmpy/crystal/wulff.py
def perpendicular_vector(p, q, r):
    "a unit vector perpendicular to the triangle p q r"
    perp_vector = np.cross(q - p, r - p)
    dp = np.dot(perp_vector, p)
    if dp > 0:
        return perp_vector / np.linalg.norm(perp_vector)
    else:
        return - perp_vector / np.linalg.norm(perp_vector)

winding_order_ccw(points)

return the indices to reorder the provided 2D points into CCW order

Source code in chmpy/crystal/wulff.py
def winding_order_ccw(points):
    "return the indices to reorder the provided 2D points into CCW order"
    centroid = points[0]
    directions = points[1:] - centroid
    directions /= np.linalg.norm(directions, axis=1)[:, np.newaxis]
    idxs = list(range(1, points.shape[0]))
    return [0] + sorted(idxs, key=lambda x: np.arctan2(directions[x - 1, 1], directions[x - 1, 0]))