Skip to main content

Function: trajectoryTube()

trajectoryTube(points, o): TubeMesh

Defined in: packages/sdvplot/src/three/tube.ts:137

A tube along a 3D polyline (a pitch, a ball flight, a skater's path) as plain mesh buffers, in the points' own world units: ready for new BufferGeometry() in three.js, or the <Trajectory> component in sdvplot/react for react-three-fiber. The tube is radius round (world units, not px), one ring of radialSegments vertices at each point, the rings turned along the path without twisting (each ring's frame is the last one's, carried along: a parallel-transport frame), with open ends. Its colour is color, or the team's (team and league; background makes it read against the scene, as teamColorPalette does); draw it with that colour unlit and not tone-mapped (MeshBasicMaterial, toneMapped: false) to show the team's colour as it is. A repeated point is skipped.

Parameters​

points​

readonly Point3[]

o​

TrajectoryTubeOptions

Returns​

TubeMesh

Example​

import { loadLeague } from "@sportsdataverse/sdvplot";
import { statcastPitchPath, trajectoryTube } from "@sportsdataverse/sdvplot/three";

await loadLeague("mlb");
// a 96.3 mph four-seamer, Yankees at Red Sox, 2024-06-15 (Baseball Savant: game 746946, at-bat 48, pitch 4)
const pitch = {
vx0: -6.245145230392043, vy0: -140.0548111003631, vz0: -4.647911601289857,
ax: 12.681580763686934, ay: 32.15363682007945, az: -12.428443024407864,
plate_x: 0.42927397039380755, plate_z: 3.546869816011372, release_pos_y: 54.12, game_year: 2024,
};
const tube = trajectoryTube(statcastPitchPath(pitch), { radius: 0.121, team: "NYY", league: "mlb" });
// in three.js: geometry.setAttribute("position", new BufferAttribute(tube.positions, 3)), and so on
tube.color;