Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions mplbasketball/court.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __init__(self, court_type="nba", origin="top-left", units="ft"):
"bottom-left",
"top-right",
"bottom-right",
"hoop"
], "Invalid origin. Choose from 'center', '(top/bottom)-(left/right)'"
assert units in ["m", "ft"], "Invalid units. Currently only 'm' and 'ft' are supported"

Expand Down Expand Up @@ -119,6 +120,12 @@ def __init__(self, court_type="nba", origin="top-left", units="ft"):
-self.court_parameters["court_dims"][1] / 2,
]
)
elif origin == "hoop":
self.origin = np.array([
(self.court_parameters['court_dims'][0] / 2) -
self.court_parameters['hoop_distance_from_edge'],
0.0
])

def draw(
self,
Expand Down
15 changes: 10 additions & 5 deletions mplbasketball/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def transform(x, y, fr, to, origin, court_dims=[94.0, 50.0]):
def transform(x, y, fr, to, origin, court_parameters):
"""
Function to transform a set of x, y values to match orientations desired for plotting.

Expand Down Expand Up @@ -28,13 +28,18 @@ def transform(x, y, fr, to, origin, court_dims=[94.0, 50.0]):
if origin == "center":
center_court = [0.0, 0.0]
elif origin == "top-left":
center_court = [court_dims[0] / 2, -court_dims[1] / 2]
center_court = [court_parameters['court_dims'][0] / 2, -court_parameters['court_dims'][1] / 2]
elif origin == "bottom-left":
center_court = [court_dims[0] / 2, court_dims[1] / 2]
center_court = [court_parameters['court_dims'][0] / 2, court_parameters['court_dims'][1] / 2]
elif origin == "top-right":
center_court = [-court_dims[0] / 2, -court_dims[1] / 2]
center_court = [-court_parameters['court_dims'][0] / 2, -court_parameters['court_dims'][1] / 2]
elif origin == "bottom-right":
center_court = [-court_dims[0] / 2, court_dims[1] / 2]
center_court = [-court_parameters['court_dims'][0] / 2, court_parameters['court_dims'][1] / 2]
elif origin == "hoop":
center_court = [
- (court_parameters['court_dims'][0] / 2) + court_parameters['hoop_distance_from_edge'],
0.0
]

if fr == to:
return x, y
Expand Down