emel/math/geometry
Functions
pub fn centroid(points: List(List(Float))) -> List(Float)
The arithmetic mean position of the points
.
Points = [
[0.0, 0.0],
[0.0, 1.0],
[1.0, 0.0],
[1.0, 1.0]
],
emel@math@geometry:centroid(Points).
% [0.5, 0.5]
pub fn dot_product(x: List(Float), y: List(Float)) -> Float
The sum of the products of the corresponding entries of x
and y
.
X = [1.0, 2.0, 3.0],
Y = [4.0, -5.0, 6.0],
emel@math@geometry:dot_product(X, Y).
% 12.0
pub fn euclidean_distance(
x: List(Float),
y: List(Float),
) -> Float
The ordinary straight-line distance between two points in Euclidean space.
X = [2.0, -1.0],
Y = [-2.0, 2.0],
emel@math@geometry:euclidean_distance(X, Y).
% 5.0
pub fn magnitude(vector: List(Float)) -> Float
The euclidean distance between the initial and the terminal point of the vector
.
Vector = [6.0, 8.0],
emel@math@geometry:magnitude(Vector).
% 10.0
pub fn nearest_neighbor(
point: List(Float),
neighbors: List(List(Float)),
) -> List(Float)
The neighbor that is closest to the given point
.
Point = [0.9, 0.0],
Neighbors = [
[0.0, 0.0],
[0.0, 0.1],
[1.0, 0.0],
[1.0, 1.0]
],
emel@math@geometry:nearest_neighbor(Point, Neighbors).
% [1.0, 0.0]