Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions csa/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,50 @@ def euclidMetric3d (g1, g2 = None):
"""
g2 = g1 if g2 == None else g2
return lambda i, j: euclidDistance3d (g1 (i), g2 (j))


def taxicabDistance2d(p1, p2):
"""Returns the taxicab (Manhattan) distance in 2D between two points
:param p1: The first point
:type p1: tuple (x, y)
:param p2: The second point
:type p2: tuple (x, y)
:return: The taxicab distance
:rtype: float
"""
return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

def taxicabMetric2d(g1, g2=None):
"""Returns a taxicab metric for 2D points
:param g1: The first group of points
:type g1: callable
:param g2: The second group of points. If None, the first group of points is used
:type g2: callable
:return: A 2D taxicab metric function
:rtype: function
"""
g2 = g1 if g2 is None else g2
return lambda i, j: taxicabDistance2d(g1(i), g2(j))

def taxicabDistance3d(p1, p2):
"""Returns the taxicab (Manhattan) distance in 3D between two points
:param p1: The first point
:type p1: numpy.array((3))
:param p2: The second point
:type p2: numpy.array((3))
:return: The taxicab distance
:rtype: float
"""
return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1]) + abs(p1[2] - p2[2])

def taxicabMetric3d(g1, g2=None):
"""Returns a taxicab metric for 3D points
:param g1: The first group of points
:type g1: callable
:param g2: The second group of points. If None, the first group of points is used
:type g2: callable
:return: A 3D taxicab metric function
:rtype: function
"""
g2 = g1 if g2 is None else g2
return lambda i, j: taxicabDistance3d(g1(i), g2(j))