Voronoi 图
🌐 Voronoi diagrams
给定一组点,Voronoi 图将平面划分为表示平面中最靠近相应点的区域的单元。Voronoi 图是 Delaunay 三角剖分 的对偶图。
🌐 Given a set of points, the Voronoi diagram partitions the plane into cells representing the region of the plane that is closest to the corresponding point. The Voronoi diagram is the dual of the Delaunay triangulation.
delaunay.voronoi(bounds)
来源 · 返回给定 Delaunay 三角剖分 的 Voronoi 图。渲染时,图形将被裁剪到指定的 边界 = [xmin, ymin, xmax, ymax]。
const delaunay = d3.Delaunay.from([[0, 0], [0, 100], [100, 0], [100, 100]]);
const voronoi = delaunay.voronoi([0, 0, 640, 480]);如果未指定 bounds,则默认为 [0, 0, 960, 500]。即使在不存在三角剖分的退化情况下——即 0、1 或 2 个点,以及共线点——也会返回 Voronoi 图。
🌐 If bounds is not specified, it defaults to [0, 0, 960, 500]. The Voronoi diagram is returned even in degenerate cases where no triangulation exists — namely 0, 1 or 2 points, and collinear points.
voronoi.delaunay
Voronoi 图的相关 Delaunay 三角剖分。
🌐 The Voronoi diagram’s associated Delaunay triangulation.
voronoi.circumcenters
德劳内三角形的外心以 Float64Array 的形式表示 [cx0, cy0, cx1, cy1, …]。每一对连续的坐标 cx, cy 对应相应三角形的外心。这些外心构成了 Voronoi 单元多边形的坐标。
🌐 The circumcenters of the Delaunay triangles as a Float64Array [cx0, cy0, cx1, cy1, …]. Each contiguous pair of coordinates cx, cy is the circumcenter for the corresponding triangle. These circumcenters form the coordinates of the Voronoi cell polygons.
voronoi.矢量
🌐 voronoi.vectors
一个 Float64Array [vx0, vy0, wx0, wy0, …],其中每个非零四元组描述外壳上的一个开放(无限)单元,给出两条开放半直线的方向。
🌐 A Float64Array [vx0, vy0, wx0, wy0, …] where each non-zero quadruple describes an open (infinite) cell on the outer hull, giving the directions of two open half-lines.
voronoi.xmin
voronoi.ymin
voronoi.xmax
voronoi.ymax
用于渲染Voronoi图的视口边界 [xmin、ymin、xmax、ymax]。这些值只影响渲染方法(voronoi.render、voronoi.renderBounds、voronoi.renderCell)。
🌐 The bounds of the viewport [xmin, ymin, xmax, ymax] for rendering the Voronoi diagram. These values only affect the rendering methods (voronoi.render, voronoi.renderBounds, voronoi.renderCell).
voronoi.contains(i, x, y)
来源 · 如果具有指定索引 i 的单元格包含指定点 ⟨x, y⟩,则返回 true;也就是说,判断点 i 是否是图中最接近指定点的点。(此方法不受关联的 Voronoi 图的视口 边界 影响。)
voronoi.neighbors(i)
voronoi.neighbors(-1) // []来源 · 返回一个可迭代对象,该对象包含与指定单元格 i 共享公共边的单元格的索引。Voronoi 邻居总是在 Delaunay 图上的邻居,但当公共边被 Voronoi 图的视口裁剪掉时,反之则不成立。
voronoi.render(context)
来源 · 将Voronoi单元的网格渲染到指定的context。指定的context必须实现来自CanvasPathMethods API的context.moveTo和context.lineTo方法。如果未指定context,则返回SVG路径字符串。
voronoi.renderBounds(context)
来源 · 将视口范围呈现到指定的 context。指定的 context 必须实现来自 CanvasPathMethods API 的 context.rect 方法。等同于 context.rect(voronoi.xmin, voronoi.ymin, voronoi.xmax - voronoi.xmin, voronoi.ymax - voronoi.ymin)。如果未指定 context,则返回 SVG 路径字符串。
voronoi.renderCell(i, context)
来源 · 将指定索引 i 的单元格渲染到指定的 context。指定的 context 必须实现来自 CanvasPathMethods API 的 context.moveTo、context.lineTo 和 context.closePath 方法。如果未指定 context,则返回 SVG 路径字符串。
voronoi.cellPolygons()
来源 · 返回一个可迭代对象,包含每个单元格的非空多边形,单元格索引作为属性。另请参见 voronoi.renderCell。
voronoi.cellPolygon(i)
来源 · 返回表示指定点 i 的单元格的凸闭多边形 [[x0, y0], [x1, y1], …, [x0, y0]]。另请参见 voronoi.renderCell。
voronoi.update()
来源 · 在点被就地修改后更新 Voronoi 图和底层的三角剖分 — 对 Lloyd 放松很有用。在底层 Delaunay 三角剖分上调用 delaunay.update。