#math #science

sphrs

Spherical harmonics and solid harmonics

5 releases

0.1.3 Jul 24, 2021
0.1.2 Dec 29, 2019
0.1.1 Dec 29, 2019
0.1.0 Dec 29, 2019
0.0.1 Oct 22, 2019

#8 in #science

MIT/Apache

255KB
981 lines

sphrs CI Gitter chat

sphrs

sphrs is a general purpose spherical/solid harmonics library in Rust.

Documentation: stable, master.

Types of spherical/solid harmonics

This crate supports these types of real and complex functions via the enums RealSHType and ComplexSHType:

Usage

Add this to your Cargo.toml:

[dependencies]
sphrs = "0.1.3"

Examples

Compute the complex spherical harmonic function of degree 2 and order 1 at (spherical) position (r = 1.0, theta = PI/4, phi = PI/4):

use sphrs::{ComplexSHType, Coordinates, SHEval};
use std::f64::consts::PI;

let sh = ComplexSHType::Spherical;
let degree = 2;
let order = 1;
let p: Coordinates<f64> = Coordinates::spherical(1.0, PI/4.0, PI/8.0);
println!("SH ({}, {}): {:?}", degree, order, sh.eval(degree, order, &p));

Compute all real SH up to 5th degree at (Cartesian) position (1, 0, 0):

use sphrs::{RealSHType, HarmonicsSet, Coordinates};
let degree = 5;
let sh: HarmonicsSet<f64, _, _> = HarmonicsSet::new(degree, RealSHType::Spherical);
let p = Coordinates::cartesian(1.0, 0.0, 0.0);
println!("SH up to degree {}: {:?}", degree, sh.eval(&p));

Acknowledgements

This crate is heavily inspired by Google's spherical-harmonics library and follows the design documented here.

References

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

License: MIT OR Apache-2.0

Dependencies