Skip to main content

Units: a court in metres, and the converters

  • court.units: m
  • court.bbox (m): -16.76, -9.14, 16.76, 9.14
  • convertUnits(94, 'ft', 'm'): 28.651
  • convertPoints([[47, 25]], 'ft', 'yd'): [[15.666666666666666,8.333333333333334]]
  • normalizeUnit('Metres'): m
  • FT_PER_UNIT.m: 3.2808
import { FT_PER_UNIT, convertPoints, convertUnits, normalizeUnit, surface } from "@sportsdataverse/sporty";
import { toSVG } from "@sportsdataverse/sporty/svg";

// `units` rebuilds the scene in another unit: every coordinate and the bbox are in metres here.
const court = surface("basketball", "nba", { units: "m" });

const facts = {
"court.units": court.units,
"court.bbox (m)": court.bbox.map((v) => v.toFixed(2)).join(", "),
"convertUnits(94, 'ft', 'm')": convertUnits(94, "ft", "m").toFixed(3),
"convertPoints([[47, 25]], 'ft', 'yd')": JSON.stringify(convertPoints([[47, 25]], "ft", "yd")),
"normalizeUnit('Metres')": normalizeUnit("Metres"),
"FT_PER_UNIT.m": FT_PER_UNIT.m.toFixed(4),
};

const list = Object.entries(facts)
.map(([k, v]) => `<li><code>${k}</code>: ${v}</li>`)
.join("");
`<figure style="margin:0">${toSVG(court, { width: 560, arcs: "svg" })}<figcaption><ul>${list}</ul></figcaption></figure>`;

Tags: units · convertUnits · convertPoints · normalizeUnit · FT_PER_UNIT · basketball · nba. All sporty examples.