collision v0.3.1 Collision.Polygon.Edge
An edge; the connection between two vertices.
Represented as a point, the next point that its connected to, and the length between them.
Summary
Functions
Calculate the angle between three vertices, A -> B -> C, based on the edges AB and BC
Calculate the distance between two vertices
Build an edge from a pair of vertices
Types
Functions
Calculate the angle between three vertices, A -> B -> C, based on the edges AB and BC.
Returns: angle B, in radians
Example
iex> a = Edge.from_vertex_pair({%Vertex{x: 4, y: 4}, %Vertex{x: 0, y: 4}})
iex> b = Edge.from_vertex_pair({%Vertex{x: 0, y: 4}, %Vertex{x: 0, y: 0}})
iex> Edge.calculate_angle(a, b)
:math.pi / 2
Specs
calculate_angle(Collision.Polygon.Edge.t, Collision.Polygon.Edge.t) ::
float |
{:error, String.t}
Specs
calculate_length({%{x: number, y: number}, %{x: number, y: number}}) :: float
Calculate the distance between two vertices.
Returns: float
Examples
iex> Edge.calculate_length({%Vertex{x: 0, y: 0}, %Vertex{x: 0, y: 4}})
4.0
iex> Edge.calculate_length({%Vertex{x: 3, y: 0}, %Vertex{x: 0, y: 4}})
5.0
Specs
from_vertex_pair({Collision.Polygon.Vertex.t, Collision.Polygon.Vertex.t}) ::
t |
{:error, String.t}
Build an edge from a pair of vertices.
Returns: Edge.t | {:error, String.t}
Example
iex> Edge.from_vertex_pair({%Vertex{x: 0, y: 0}, %Vertex{x: 0, y: 4}})
%Edge{point: %Vertex{x: 0, y: 0}, next: %Vertex{x: 0, y: 4}, length: 4.0}