View Source Scenic.Math.Line (Scenic v0.11.2)

A collection of functions to work with lines.

Lines are always two points in a tuple.

{point_a, point_b}
{{x0, y0}, {x1, y1}}

Link to this section Summary

Functions

Find the point of intersection between two lines.

Find a new line that is parallel to the given line and separated by the given distance.

Round the points that define a line so that they are made up of integers.

Truncate the points that define a line so that they are made up of integers.

Link to this section Functions

Link to this function

intersection(line_a, line_b)

View Source
@spec intersection(line_a :: Scenic.Math.line(), line_b :: Scenic.Math.line()) ::
  Scenic.Math.point()

Find the point of intersection between two lines.

Parameters:

  • line_a - A line defined by two points. {point_a, point_b}
  • line_b - A line defined by two points. {point_a, point_b}

Returns: A point

examples

Examples

iex> Scenic.Math.Line.intersection({{1, 1}, {3, 3}}, {{3, 1}, {1, 3}}) {2.0, 2.0}

Link to this function

parallel(line, distance)

View Source
@spec parallel(line :: Scenic.Math.line(), distance :: number()) :: Scenic.Math.line()

Find a new line that is parallel to the given line and separated by the given distance.

Parameters:

  • line - A line defined by two points. {point_a, point_b}
  • distance - The perpendicular distance to the new line.

Returns: A line

examples

Examples

iex> Scenic.Math.Line.parallel({{1, 1}, {1, 2}}, 2)
{{3.0, 1.0}, {3.0, 2.0}}
@spec round(line :: Scenic.Math.line()) :: Scenic.Math.line()

Round the points that define a line so that they are made up of integers.

Parameters:

  • line - A line defined by two points. {point_a, point_b}

Returns:

A line

examples

Examples

iex> Scenic.Math.Line.round({{1.5, 1.6}, {2.1, 2.56}})
{{2, 2}, {2, 3}}
@spec trunc(line :: Scenic.Math.line()) :: Scenic.Math.line()

Truncate the points that define a line so that they are made up of integers.

Parameters:

  • line - A line defined by two points. {point_a, point_b}

Returns:

A line

examples

Examples

iex> Scenic.Math.Line.trunc({{1.1, 1.1}, {2.0, 2.0}})
{{1, 1}, {2, 2}}
iex> Scenic.Math.Line.trunc({{-1, 1}, {-2.0, 2.0}})
{{-1, 1}, {-2, 2}}