Skip to main content

Function: add_shot_distance_angle()

add_shot_distance_angle(pbp, goal_x?): Row[]

Defined in: src/analytics/hockeytech.ts:545

Add shot_distance / shot_angle (feet / degrees) for shot-type events, null elsewhere.

Parameters​

pbp​

Row[]

Play-by-play rows whose x_coord / y_coord are in rink FEET (net near +goal_x, centre ice at 0). Rows with event in shot, blocked_shot, goal get values.

goal_x?​

number = NHL_SIZE_RINK_GOAL_X

Offensive goal-line x in feet, 0 < goal_x <= 110. Default NHL_SIZE_RINK_GOAL_X (89 ft).

Returns​

Row[]

A new array of copied rows with shot_distance (feet from the net: sqrt(dx^2 + y^2)) and shot_angle (degrees off the goal line's normal, |atan2(|y|, dx)|); null for non-shot events and for null coordinates. dx is goal_x - |x| (the nearer net) except for an empty-net goal, see remarks.

Throws​

RangeError when goal_x is outside (0, 110] — the guard against passing raw feed-scale coordinates.

Example​

import { add_shot_distance_angle } from "sportsdataverse/dist/analytics/hockeytech.js";
const rows = add_shot_distance_angle(rinkFeetPbp); // default 89 ft net
const olympic = add_shot_distance_angle(rinkFeetPbp, 80); // custom goal line

Remarks​

Distance is to the nearer net: an own-half event with a goalie in net is a near-net event whose coordinates the feed mirrored. An empty-net goal (empty_net "1", the goal-level field parse_pbp takes from properties.isEmptyNet) is measured to the net its team attacks instead, dx = |attack_x - x|: the feed puts the home team's attack at x = -goal_x and the visitor's at +goal_x, and an own-half empty-net goal is a genuine long shot. When team_id or home_team_id is null, '' or absent the side is unknown and the nearer net is kept. Validated per event on 320 PWHL games (sdv-internal-refs #52, hockeytech/CANVAS.md). enrich_pbp calls this on the rink-feet frame it derives from x_coord_original / y_coord_original.