API
GeometrySDF.SignedDistanceField — Type
SignedDistanceField(grid, ϕ)A signed distance field (SDF) defined on a Cartesian grid.
This type is the return value of sdf. The scalar field values are stored in ϕ with the same shape as grid.
Fields
grid: Sampling grid (providesaxesand spacing).ϕ: Signed distance values on the grid nodes.
Interpolation (external)
This package does not bundle interpolation. You can interpolate ϕ using Interpolations.jl (or similar) by passing the grid axes and the field values.
Examples
julia> using Interpolations
julia> itp = linear_interpolation(sdf.grid.axes, sdf.ϕ);GeometrySDF.sdf — Function
sdf(path::String; spacing=:auto, minres=128, padding=1, datatype=Float64, progress=false)Generate a 3D signed distance field (SDF) from a triangle mesh file.
Arguments
path: Path to a mesh file supported by MeshIO.jl.
Keyword arguments
spacing: Grid spacing. Use a number or:auto(chosen from the mesh bounding box usingminres).minres: Minimum resolution along the longest bounding-box axis whenspacing=:auto.padding: Extra margin around the mesh in multiples of the grid spacing.datatype: Floating-point type used for computation (default:Float64).progress: Show progress meter.
sdf(points; spacing=:auto, minres=128, padding=1, datatype=Float64, progress=false)Generate a 2D signed distance field (SDF) from a closed polyline.
The polyline is closed implicitly by connecting the last point back to the first.
Arguments
points: Either- a 2×N matrix (each column is a vertex), or
- a vector of 2D vertices (
StaticVector{2}).
Keyword arguments
spacing: Grid spacing. Use a number or:auto(chosen fromminres).minres: Minimum resolution along the longest bounding-box axis whenspacing=:auto.padding: Extra margin around the polyline in multiples of the grid spacing.datatype: Floating-point type used for computation (default:Float64).progress: Show progress meter.
Examples
julia> sdf = GeometrySDF.sdf([0.0 1.0; 0.2886751346 0.5; 0.8660254038 0.5; 0.5773502692 0.0; 0.8660254038 -0.5; 0.2886751346 -0.5; 0.0 -1.0; -0.2886751346 -0.5; -0.8660254038 -0.5; -0.5773502692 0.0; -0.8660254038 0.5; -0.2886751346 0.5]');
julia> GeometrySDF.writevtk("hexagram", sdf)
1-element Vector{String}:
"hexagram.vti"GeometrySDF.writevtk — Function
writevtk(path::String, sdf::SignedDistanceField)Write a SignedDistanceField to a VTK structured grid file.
The output stores the grid coordinates (sdf.grid.axes) and the signed distance values (sdf.ϕ) as a scalar field named "Signed distance" for visualization in ParaView.
Arguments
path: Output file path (without extension is fine; WriteVTK.jl will append as needed).sdf: Signed distance field generated bysdf.