You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

#### 55 lines 2.0 KiB Raw Blame History

 `use nalgebra::{Vector4};` `pub type HypVec3 = Vector4;` `/// Lorentz inner product of two vectors` `pub fn lorentz(a: HypVec3, b: HypVec3) -> f64 {` ` a * b + a * b + a * b - a * b` `}` `pub fn lorentz_norm(a: HypVec3) -> f64 {` ` lorentz(a, a)` `}` `pub fn normalize_timelike(a: HypVec3) -> Option {` ` let n = -lorentz_norm(a);` ` if !(n > 0.0) {` ` None` ` } else {` ` Some(a * n.sqrt().recip())` ` }` `}` `pub fn normalize_spacelike(a: HypVec3) -> Option {` ` let n = lorentz_norm(a);` ` if !(n > 0.0) {` ` None` ` } else {` ` Some(a * n.sqrt().recip())` ` }` `}` `/// Represents a line (or a ray) in hyperbolic space.` `pub struct Line {` ` /// A point that the line passes through.` ` timelike: HypVec3,` ` /// A spacelike unit representing the direction of the line or ray. ` ` direction: HypVec3,` `}` `/// Represents a surface with constant curvature. In the hyperboloid representation of the space, the surface represents the points whose Lorentz inner product with `direction` is equal to `offset`.` `pub struct Surface {` ` /// The vector whose Lorentz inner product with each point on the surface is constant. If this is timelike, the surface is a sphere, and this is its center. If this is spacelike, the surface is hypercyclic, and this is its plane. Otherwise, the surface is horocyclic, and this represents the convergence point of its perpendiculars.` ` direction: HypVec3,` ` /// If `direction` is a timelike unit, this is the negation of the hyperbolic cosine of the radius of the sphere around the corresponding point; if `direction` is a spacelike unit, this is the hyperbolic sine of the distance from the corresponding plane.` ` offset: f64,` `}` `impl Line {` ` /// Create a ray from timelike unit `from` to `to`.` ` fn new_ray(from: HypVec3, to: HypVec3) -> Option {` ` let timelike = from;` ` let direction = normalize_spacelike((to - from) + timelike * lorentz(timelike, (to - from)))?;` ` Some(Line { timelike, direction })` ` }` ```} ```