Crates.io | csg_surface_distance |
lib.rs | csg_surface_distance |
version | 0.1.0 |
source | src |
created_at | 2024-10-22 23:16:07.271839 |
updated_at | 2024-10-22 23:16:07.271839 |
description | A package for calculating distance along a given vector between a point and a constructive solid geometry surface |
homepage | https://github.com/fusion-energy/csg_surface_distance |
repository | https://github.com/fusion-energy/csg_surface_distance |
max_upload_size | |
id | 1419433 |
size | 16,402 |
A Rust Cargo crate for finding the distance between a point and a constructive solid geometry (CSG) surface
This example finds the distance from a point along a vector to a spherical surface.
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.");
}
}
csg_surface_distance supports the following types of surfaces:
Sphere
(x, y, z)
and radius.CSGSurface::Sphere { x: 0.0, y: 0.0, z: 0.0, radius: 1.0 }
XPlane
CSGSurface::XPlane { x: 2.0 }
YPlane
CSGSurface::YPlane { y: 2.0 }
ZPlane
CSGSurface::ZPlane { z: 2.0 }
Plane
ax + by + cz + d = 0
.CSGSurface::Plane { a: 1.0, b: 1.0, c: 1.0, d: -3.0 }
XAxisCylinder
(y, z)
and radius.CSGSurface::XAxisCylinder { y: 0.0, z: 0.0, radius: 1.0 }
YAxisCylinder
(x, z)
and radius.CSGSurface::YAxisCylinder { x: 0.0, z: 0.0, radius: 1.0 }
ZAxisCylinder
(x, y)
and radius.CSGSurface::ZAxisCylinder { x: 0.0, y: 0.0, radius: 1.0 }
Quadric
Ax^2 + By^2 + Cz^2 + Dxy + Eyz + Fxz + Gx + Hy + Jz + K = 0
.CSGSurface::Quadric { a: 1.0, b: 1.0, c: 1.0, d: 0.0, e: 0.0, f: 0.0, g: 0.0, h: 0.0, j: 0.0, k: -3.0 }
To use the csg_surface_distance
package, add it to your Cargo.toml
:
[dependencies]
csg_surface_distance = "0.1.0" # Replace with the actual version