pub struct Sphere2<'a, T = f64> { /* private fields */ }Expand description
A Euclidean sphere, that is, a set given by $S_2^r = \{x \in \mathbb{R}^n {}:{} \Vert{}x{}\Vert = r\}$ or a Euclidean sphere centered at a point $x_c$, that is, $S_2^{x_c, r} = \{x \in \mathbb{R}^n {}:{} \Vert{}x-x_c{}\Vert = r\}$
Implementations§
Source§impl<'a, T: Float> Sphere2<'a, T>
impl<'a, T: Float> Sphere2<'a, T>
Sourcepub fn new(center: Option<&'a [T]>, radius: T) -> Self
pub fn new(center: Option<&'a [T]>, radius: T) -> Self
Construct a new Euclidean sphere with given center and radius
If no center is given, then it is assumed to be in the origin
§Example
use optimization_engine::constraints::{Constraint, Sphere2};
let sphere = Sphere2::new(None, 1.0);
let mut x = [3.0, 4.0];
sphere.project(&mut x).unwrap();Trait Implementations§
Source§impl<'a, T> Constraint<T> for Sphere2<'a, T>
impl<'a, T> Constraint<T> for Sphere2<'a, T>
Source§fn project(&self, x: &mut [T]) -> FunctionCallResult
fn project(&self, x: &mut [T]) -> FunctionCallResult
Projection onto the sphere, $S_{r, c}$ with radius $r$ and center $c$. If $x\neq c$, the projection is uniquely defined by
$$ P_{S_{r, c}}(x) = c + r\frac{x-c}{\Vert{}x-c\Vert_2}, $$
but for $x=c$, the projection is multi-valued. In particular, let $y = P_{S_{r, c}}(c)$. Then $y_1 = c_1 + r$ and $y_i = c_i$ for $i=2,\ldots, n$.
§Arguments
x: The given vector $x$ is updated with the projection on the set
§Panics
Panics if x is empty or, when a center is provided, if x and
center have incompatible dimensions.