csg_surface_distance

Crates.iocsg_surface_distance
lib.rscsg_surface_distance
version0.1.0
sourcesrc
created_at2024-10-22 23:16:07.271839
updated_at2024-10-22 23:16:07.271839
descriptionA package for calculating distance along a given vector between a point and a constructive solid geometry surface
homepagehttps://github.com/fusion-energy/csg_surface_distance
repositoryhttps://github.com/fusion-energy/csg_surface_distance
max_upload_size
id1419433
size16,402
Jonathan Shimwell (shimwell)

documentation

https://github.com/fusion-energy/csg_surface_distance

README

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
Commit count: 17

cargo fmt