diff --git a/README.md b/README.md index c1d7459..39e1b6f 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,27 @@ A Rust Cargo crate for finding the distance between a point and a constructive solid geometry (CSG) surface +## Example usage + +This example finds the distance from a point along a vector to a spherical surface. + +```rust +use csg_distance::{Point, Vector, CSGSurface}; + +fn main() { + let point = Point { x: 1.0, y: 2.0, z: 3.0 }; + let vector = Vector { dx: 1.0, dy: 0.0, dz: 0.0 }; + + let surface = CSGSurface::Sphere { x: 0.0, y: 0.0, z: 0.0, radius: 1.0 }; + + if let Some(distance) = surface.distance_to_surface(&point, &vector) { + println!("Distance to surface: {}", distance); + } else { + println!("No intersection with the surface."); + } +} +``` + ## Supported Surfaces csg_surface_distance supports the following types of surfaces: