This module contains two different type for repesenting a 2D Point:
Location and Vector. The idea is to use Locations to store a Point and Vector
to do caluclations. This way the compiler knows exactly what you are doing and can
give you appropriate error messages.
An Angle can be constructed from a Vector.
{x=0,y=0} |> Location.toAngle
--> 0A Location a point, possibly stored in a dictionary. Thats why its a tuple.
But doing calulations with tuples can get very chaotic, thats why the module provides
Vectors.
given a Location, a distance in some direction. This is the most used
way how to change a location.
(0,0) |> move 1 (Angle 0)
--> (1,0)simple adds a vector to a location, from geometry we know that a vector is actually just an angle and a length.
add ( fromAngle angle |> scaleby length)
--> move length angleThe difference between to locations is a vector.
loc1 <----- loc2the resulting vector points from the second value to the first.
(1,0) |> vectorTo (1,1)
--> { x = 0, y = 1 }A Vector is used for calculations.
construct a unit vector from an angle
fromAngle (Angle (pi/4) )
|> length
--> 1The Distance between two locations is the length of the resulting vector
distance == vectorTo >> lengthrotate a Vector
{ x = 1, y = 0 } |> rotate (Angle (pi/2))
--> {x = 0, y = -1}Scales a Vector. Vectors obtained by fromAngle have size 1.
fromAngle (Angle (pi/4) ) |> scaleBy 42 |> length
--> 42Returns the length of the coordinate (distance to (0,0)
A Angle should store Elm angles (radians).
Use the functions
degrees,radias,turnsorpito obtain a Angle.