Published
Edited
Oct 17, 2021
1 fork
Importers
32 stars
Insert cell
Insert cell
Insert cell
Insert cell
// from absolute cube coords to cube coords relative to big hex center
function rel_coords(xyz) {
const [x,y,z] = xyz;
const ijk = small_to_big(xyz)
const [xc,yc,zc] = center_of(ijk);
return [x-xc,y-yc,z-zc];
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// from absolute (or relative) cube coords to one integer
function hexmod(xyz) {
const [x,y,z]=xyz;
const m = my.mod(y+s*x, A);
return m;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function inv_hexmod(m) {
const ms = my.div(m+r,s),
mcs = my.div(m+2*r,s-1);
const x = ms*(r+1) + mcs*-r,
y = m + ms*(-2*r-1) + mcs*(-r-1),
z = -m + ms*r + mcs*(2*r+1);
return [x,y,z];
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more