A direction can be though of as a normalized vector or can be though of just something pointing in a particular
direction on the 2D cartesian plane. When looking at the type of a direction, you can notice that it doesn't have any
unit type, Direction2D<'Coordinates>
. This is because a direction always has a magnitude of 1 and doesn't need any
unit qualifier.
# Builders
Direction2D.xy
first checks to make sure that the input components are both non-zero, then normalizes them to
guarantee a valid direction is created.
Direction2D.xy 3. 4.
No value returned by any evaluator
|
When both values are zero, a proper direction cannot be created, so the program returns a None
option.
(Appears as <null>
in the terminal)
Direction2D.xy 0. 0.
No value returned by any evaluator
|
You can also create a direction using similar functionality to Direction2D.xy
but with tuples as an input instead.
Direction2D.fromComponents (3., 4.)
No value returned by any evaluator
|
Direction2D.positiveX
Direction2D.x
Direction2D.positiveY
Direction2D.y
Direction2D.negativeX
Direction2D.negativeY
Direction2D.toAngle
Direction2D.toTuple
Direction2D.xComponent
direction.X
Direction2D.yComponent
direction.Y
Direction2D.reverse
Direction2D.rotateClockwise
Direction2D.rotateCounterclockwise
Direction2D.perpendicularTo
Direction2D.mirrorAcross
Direction2D.orthonormalize
Direction2D.equalWithin
Direction2D.componentIn
Direction2D.angleFrom
Direction2D.relativeTo
Direction2D.placeIn
namespace Math
namespace Math.Geometry
Multiple items
union case Cartesian.Cartesian: Cartesian
--------------------
type Cartesian = | Cartesian
Multiple items
module Direction2D
from Math.Geometry
--------------------
type Direction2D<'Coordinates> =
{ X: float
Y: float }
interface IComparable
interface IComparable<Direction2D<'Coordinates>>
interface IGeometry<'Coordinates>
member Comparison : other:Direction2D<'Coordinates> -> int
override Equals : obj:obj -> bool + 1 overload
override GetHashCode : unit -> int
member LessThan : other:Direction2D<'Coordinates> -> bool
static member xy : x:float -> y:float -> Direction2D<'Coordinates> option
Multiple items
val xy : x:float -> y:float -> Direction2D<'Coordinates> option
<summary>
Get a direction vector from the x and y components. This function takes
care of normalizing the x and y components into the unit direction vector.
This function also checks for the edge case where the x and y components
are both zero. In that case, the function returns `None`.
</summary>
--------------------
static member Direction2D.xy : x:float -> y:float -> Direction2D<'Coordinates> option
module Option
from Microsoft.FSharp.Core
<summary>Contains operations for working with options.</summary>
<category>Options</category>
val map : mapping:('T -> 'U) -> option:'T option -> 'U option
<summary><c>map f inp</c> evaluates to <c>match inp with None -> None | Some x -> Some (f x)</c>.</summary>
<param name="mapping">A function to apply to the option value.</param>
<param name="option">The input option.</param>
<example><code>
None |> Option.map (fun x -> x * 2) // evaluates to None
Some 42 |> Option.map (fun x -> x * 2) // evaluates to Some 84
</code></example>
<returns>An option of the input value after applying the mapping function, or None if the input is None.</returns>
val toTuple : d:Direction2D<'Coordinates> -> float * float
<summary>
{-| Get the X and Y components of a direction as a tuple (X, Y).
</summary>
val fromComponents : x:float * y:float -> Direction2D<'Coordinates> option
val positiveY<'Coordinates> : Direction2D<'Coordinates>
val toAngle : d:Direction2D<'Coordinates> -> Math.Units.Angle
<summary>
Convert a direction to a polar angle (the counterclockwise angle from the
positive X direction). The result will be in the range -180 to 180 degrees.
</summary>
val positiveX<'Coordinates> : Direction2D<'Coordinates>
val x<'Coordinates> : Direction2D<'Coordinates>
val y<'Coordinates> : Direction2D<'Coordinates>
val negativeX<'Coordinates> : Direction2D<'Coordinates>
val negativeY<'Coordinates> : Direction2D<'Coordinates>
val direction : Direction2D<Cartesian>
val xyUnsafe : x:float -> y:float -> Direction2D<'Coordinates>
<summary>
Create a direction vector from the x and y components. This function
doesn't perform either zero magnitude checks nor does it normalize the
input vectors. This function should only be used with input constants or
when you are sure that you aren't going to create a direction with an
invalid state.
</summary>
val xComponent : d:Direction2D<'Coordinates> -> float
<summary>
Get the X component of the direction.
</summary>
Direction2D.X: float
val yComponent : d:Direction2D<'Coordinates> -> float
<summary>
Get the Y component of the direction.
</summary>
Direction2D.Y: float
val reverse : direction:Direction2D<'Coordinates> -> Direction2D<'Coordinates>
val rotateClockwise : direction:Direction2D<'Coordinates> -> Direction2D<'Coordinates>
val rotateCounterclockwise : direction:Direction2D<'Coordinates> -> Direction2D<'Coordinates>
val perpendicularTo : d:Direction2D<'Coordaintes> -> Direction2D<'Coordaintes>
<summary>
Construct a direction perpendicular to the given direction, by rotating the
given direction 90 degrees counterclockwise. This is the same
`Direction2D.rotateBy (Angle.degrees 90)` but is more efficient.
Alias for `rotateCounterclockwise`.
</summary>
val mirrorAcross : axis:Axis2D<'Units,'Corodiantes> -> d:Direction2D<'Coordinates> -> Direction2D<'Coordinates>
<summary>
Mirror a direction across a particular axis. Note that only the direction of
the axis affects the result, since directions are position-independent.
</summary>
val orthonormalize : xVector:Vector2D<'Units,'Coordinates> -> xyVector:Vector2D<'Units,'Coordinatres> -> (Direction2D<'Coordinates> * Direction2D<'Coordinates>) option
<summary>
Attempt to form a pair of perpendicular directions from the two given
vectors by performing [Gram-Schmidt normalization](https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process):
* The first returned direction will be equal to the direction of the first
given vector
* The second returned direction will be as close as possible to the second
given vector while being perpendicular to the first returned direction
</summary>
val equalWithin : angle:Math.Units.Angle -> rhs:Direction2D<'Coordinates> -> lhs:Direction2D<'Coordinates> -> bool
<summary>
Compare two directions within an angular tolerance. Returns true if the
absolute value of the angle between the two given directions is less than the
given tolerance.
</summary>
val componentIn : d2:Direction2D<'Coordinates> -> d1:Direction2D<'Coordinates> -> float
<summary>
Find the component of one direction in another direction. This is equal to
the cosine of the angle between the directions, or equivalently the dot product
of the two directions converted to unit vectors.
This is more general and flexible than using `xComponent` or `yComponent`, both
of which can be expressed in terms of `componentIn`; for example,
`Direction2d.xComponent direction`
is equivalent to
`Direction2d.componentIn Direction2d.x direction`.
</summary>
val angleFrom : d1:Direction2D<'Coordinates> -> d2:Direction2D<'Coordinates> -> Math.Units.Angle
<summary>
Find the counterclockwise angle from the first direction to the
second. The result will be in the range -180 to 180 degrees
</summary>
val relativeTo : frame:Frame2D<'Units,'GlobalCoordaintes,'LocalCoordinates> -> d:Direction2D<'GlobalCoordinates> -> Direction2D<'LocalCoordaintes>
<summary>
Take a direction defined in global coordinates, and return it expressed in
local coordinates relative to a given reference frame.
</summary>
val placeIn : reference:Frame2D<'Units,'GlobalCoordinates,'LocalCoordinates> -> direction:Direction2D<'LocalCoordinates> -> Direction2D<'GlobalCoordinates>
<summary>
Take a direction defined in local coordinates relative to a given reference
frame, and return that direction expressed in global coordinates.
</summary>