csg_surface_distance 0.1.0

A package for calculating distance along a given vector between a point and a constructive solid geometry surface
Documentation
  • Coverage
  • 0%
    0 out of 50 items documented0 out of 4 items with examples
  • Size
  • Source code size: 16.08 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.81 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Documentation
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • shimwell

CI Rust testing

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.

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:

  1. Sphere

    • Defined by its center coordinates (x, y, z) and radius.
    • Example:
      CSGSurface::Sphere { x: 0.0, y: 0.0, z: 0.0, radius: 1.0 }
      
  2. XPlane

    • A plane perpendicular to the x-axis.
    • Defined by the x-coordinate of the plane.
    • Example:
      CSGSurface::XPlane { x: 2.0 }
      
  3. YPlane

    • A plane perpendicular to the y-axis.
    • Defined by the y-coordinate of the plane.
    • Example:
      CSGSurface::YPlane { y: 2.0 }
      
  4. ZPlane

    • A plane perpendicular to the z-axis.
    • Defined by the z-coordinate of the plane.
    • Example:
      CSGSurface::ZPlane { z: 2.0 }
      
  5. Plane

    • A general plane defined by the equation ax + by + cz + d = 0.
    • Example:
      CSGSurface::Plane { a: 1.0, b: 1.0, c: 1.0, d: -3.0 }
      
  6. XAxisCylinder

    • A cylinder aligned along the x-axis.
    • Defined by its center coordinates (y, z) and radius.
    • Example:
      CSGSurface::XAxisCylinder { y: 0.0, z: 0.0, radius: 1.0 }
      
  7. YAxisCylinder

    • A cylinder aligned along the y-axis.
    • Defined by its center coordinates (x, z) and radius.
    • Example:
      CSGSurface::YAxisCylinder { x: 0.0, z: 0.0, radius: 1.0 }
      
  8. ZAxisCylinder

    • A cylinder aligned along the z-axis.
    • Defined by its center coordinates (x, y) and radius.
    • Example:
      CSGSurface::ZAxisCylinder { x: 0.0, y: 0.0, radius: 1.0 }
      
  9. Quadric

    • A general quadric surface defined by the equation Ax^2 + By^2 + Cz^2 + Dxy + Eyz + Fxz + Gx + Hy + Jz + K = 0.
    • Example:
      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 }
      

Usage

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