Crates.io | centerline |
lib.rs | centerline |
version | 0.11.0 |
source | src |
created_at | 2021-02-07 16:08:59.609585 |
updated_at | 2023-12-08 16:11:00.649192 |
description | Simple library for finding centerlines of 2D closed geometry |
homepage | |
repository | https://codeberg.org/eadf/centerline_rs.git |
max_upload_size | |
id | 351968 |
size | 2,287,989 |
This simple library tries to find center-lines, aka the median-axis, of closed 2D geometries.
It is focused on letter like shapes, i.e. vertex loops with potential enclosed islands of loops. Loops directly connected to other loops does not work at the moment.
It uses a segmented voronoi diagram as a base, then it filters out the 'spiky' bits (green) by comparing the angle between the edge (green), and the input geometry (red) that created it. If the angle is close to 90°, it will be ignored. Note that the result (blue) technically is not a true centerline after the spikes has been filtered out, but it makes for much cleaner tool-paths etc. It also performs a line simplification on the resulting center-line.
let segments = ...same as boost voronoi segments...
let mut centerline = Centerline::<i32, glam::Vec3>::::with_segments(segments);
centerline.build_voronoi()?;
// the cosine value of the angle limit.
let cos_angle:f32 = 0.38;
// the RDP simplification distance
let centerline_simplification:f32 = 0.1;
centerline.calculate_centerline(cos_angle, centerline_simplification, None)?;
println!(
"Result: lines:{}, line_strings:{}",
centerline.lines.as_ref().map_or(0,|x|x.len()),
centerline.line_strings.as_ref().map_or(0,|x|x.len())
);
cargo run --example fltk_gui --features=obj-rs --release
The example only displays 2D, but the generated center-line is actually 3D line segments.
The Z coordinate is the distance between the 2D center-line, and the geometry that created it.
The example GUI takes .obj
files as input. The .obj
file needs to be 2D in some axis aligned plane (one of the coordinates needs to be zero).
Also make sure there are no intersecting outer edges.
The minimum supported version of Rust for centerline
is 1.66
.
We welcome contributions from the community. Feel free to submit pull requests or report issues on our GitHub repository. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Licensed under either of
at your option.