incremental-delaunay article
This commit is contained in:
parent
3d89ab8ce6
commit
b7727d6aa3
35
articles/incremental-delaunay/page.mmd
Normal file
35
articles/incremental-delaunay/page.mmd
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
Title: Optimized Incremental Delaunay
|
||||||
|
Brief: Classic triangulation algorithm to use for one by one insertion of points, with SIMD and caching.
|
||||||
|
Date: 1694711563
|
||||||
|
Tags: Programming, Zig, Generation
|
||||||
|
CSS: /style.css
|
||||||
|
|
||||||
|
![](/articles/incremental-delaunay/web.png)
|
||||||
|
|
||||||
|
Based on [this paper](https://www.cs.umd.edu/class/spring2020/cmsc754/Lects/lect13-delaun-alg.pdf)
|
||||||
|
|
||||||
|
Full usable isolated code is [here](/articles/incremental-delaunay/incremental-delaunay.zig.txt).
|
||||||
|
|
||||||
|
### Usage example ###
|
||||||
|
```zig
|
||||||
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
|
defer std.debug.assert(gpa.deinit() == .ok);
|
||||||
|
var triangulator = try Delaunay.Builder.init(gpa.allocator(), Delaunay.Area{-1, -1, 1, 1});
|
||||||
|
|
||||||
|
const point_count = 128;
|
||||||
|
|
||||||
|
var prng = std.rand.DefaultPrng.init(123123);
|
||||||
|
const rng = prng.random();
|
||||||
|
for (0..point_count) |_| {
|
||||||
|
const x = rng.float(f32) * 2 - 1;
|
||||||
|
const y = rng.float(f32) * 2 - 1;
|
||||||
|
try triangulator.insertAtRandom(Delaunay.Vertex{ x, y }, rng);
|
||||||
|
}
|
||||||
|
|
||||||
|
var triangles: [point_count * 2 + 2]gfx.triangle.ScreenspaceTriangle = undefined;
|
||||||
|
for (&triangles, triangulator.triangles.items) |*out, in| {
|
||||||
|
out.a = triangulator.vertices.items[in.points[0]];
|
||||||
|
out.b = triangulator.vertices.items[in.points[1]];
|
||||||
|
out.c = triangulator.vertices.items[in.points[2]];
|
||||||
|
}
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user