catenary/
lib.rs

1#![feature(iter_map_windows)]
2//! This module provides functionality for working with catenary curves.
3//!
4//! A catenary curve is defined by the equation: `y(x) = a * cosh((x - c) / a) - a + h`
5//! where:
6//! - `a` is the parameter that controls the shape of the curve.
7//! - `c` is the horizontal shift of the curve.
8//! - `h` is the vertical shift of the curve.
9//! - `s_0` and `s_1` are the arc lengths of the end points (negative on the left of the minimum, positive on the right).
10//!
11//! The module includes the following functionality:
12//! - Representation of a catenary curve with the `Catenary` structure.
13//! - Methods for creating and manipulating catenary curves.
14//! - Methods for computing various properties of catenary curves, such as the y-coordinate from a given x-coordinate, the x-coordinate from a given y-coordinate, the length of the curve, and the end points of the curve.
15//! - Methods for creating a catenary curve from two points and a specified length, with or without an initial guess.
16//! - Methods for creating a catenary curve from a line segment.
17//! - Implementation of the `LeastSquaresProblem` trait for solving catenary curve fitting problems using the Levenberg-Marquardt algorithm.
18//!
19//! The module also includes a sub-module for generating a table of catenaries (`table`) and a sub-module for working with roots (`roots`).
20//!
21//! # Examples
22//!
23//! ```rust
24//! use catenary::{CatMaker, Catenary64};
25//! use nalgebra::Point2;
26//! use approx::assert_relative_eq;
27//!
28//! let catenary = CatMaker::a(1.1).c(2.2).h(3.3).s_0(-4.4).s_1(5.5);
29//! let (p0, p1) = catenary.end_points();
30//! let solved = Catenary64::from_points_length(&p0, &p1, catenary.length()).unwrap();
31//!
32//! assert_relative_eq!(catenary.a, solved.a, epsilon = 1e-5);
33//! assert_relative_eq!(catenary.c, solved.c, epsilon = 1e-5);
34//! assert_relative_eq!(catenary.h, solved.h, epsilon = 1e-5);
35//! ```
36
37/// Module for working with catenary curves.
38pub mod catenary;
39
40/// Module for generating a table of catenaries, so we can easily interpolate between them.
41pub mod table;
42
43/// Module for working with roots.
44pub mod roots;
45
46pub use catenary::{catmaker::CatMaker, Catenary, Catenary32, Catenary64};
47pub use table::{Table, Table32, Table64};