Vectors can be created from the x and y components.
Vector2D.xy (Length.meters 3.) (Length.meters 4.)
You can also create a vector in polar coordinates.
Vector2D.rTheta (Length.meters 5.) Angle.halfPi
Using a vector direction you can create a vector of a given length following that direction.
Vector2D.withQuantity (Length.meters 5.) (Direction2D.fromAngle Angle.halfPi)
let vec: Vector2D<Meters, Cartesian> =
Vector2D.xy (Length.meters 3.) (Length.meters 4.)
vec.X = Vector2D.x vec
vec.Y = Vector2D.y vec
Vector2D.magnitude vec
No value returned by any evaluator
|
Operators are provided for more concise syntax when dealing with vectors. All
of these symbol operators have a corresponding function that you can use as
well. These are often used when using functions like List.map
or when used
in piping operations (|>
). Pay attention to the order of the arguments!
Because these functions are intended to be used in pipes the order goes like
Vector2D.add rhs lhs
.
lhs |> Vector2D.plus rhs = lhs + rhs
No value returned by any evaluator
|
The following table is the complete list of operators that can be used on
vector objects.
- |
Vector |
|
Vector |
-vec
|
Vector2D.neg
|
+ |
Vector |
Vector |
Vector |
lhs + rhs
|
Vector2D.plus
|
- |
Vector |
Vector |
Vector |
lhs - rhs
|
Vector2D.minus
|
* |
Vector |
float |
Vector |
lhs * 0.5
|
Vector2D.times & Vector2D.scaleBy
|
* |
float |
Vector |
Vector |
0.5 * rhs
|
None
|
/ |
Vector |
float |
Vector |
lhs / 4.
|
Vector2D.dividedBy
|
# Trigonometry
\[lhs \cdot rhs\]
Vector2D.dot lhs rhs
No value returned by any evaluator
|
\[ lhs \times rhs \]
Vector2D.cross lhs rhs
No value returned by any evaluator
|
namespace Math
namespace Math.Geometry
namespace Math.Units
Multiple items
union case Cartesian.Cartesian: Cartesian
--------------------
type Cartesian = | Cartesian
Multiple items
module Vector2D
from Math.Geometry
--------------------
[<Struct>]
type Vector2D<'Units,'Coordinates> =
{ X: Quantity<'Units>
Y: Quantity<'Units> }
interface IComparable
interface IComparable<Vector2D<'Units,'Coordinates>>
interface IGeometry<'Coordinates>
member Comparison : other:Vector2D<'Units,'Coordinates> -> int
override Equals : obj:obj -> bool + 1 overload
override GetHashCode : unit -> int
member LessThan : other:Vector2D<'Units,'Coordinates> -> bool
static member ( * ) : vector:Vector2D<'Units,'Coordinates> * scale:float -> Vector2D<'Units,'Coordinates> + 1 overload
static member ( + ) : lhs:Vector2D<'Units,'Coordinates> * rhs:Vector2D<'Units,'Coordinates> -> Vector2D<'Units,'Coordinates>
static member ( - ) : lhs:Vector2D<'Units,'Coordinates> * rhs:Vector2D<'Units,'Coordinates> -> Vector2D<'Units,'Coordinates>
...
val xy : x:Quantity<'Units> -> y:Quantity<'Units> -> Vector2D<'Units,'Coordinates>
<summary>
Construct a Vector2D object from the x and y lengths.
</summary>
Multiple items
module Length
from Math.Units
<category>Module: Unit System</category>
<summary>
A <c>Length</c> represents a length in meters, feet, centimeters, miles etc. It
is stored as a number of meters.
</summary>
--------------------
type Length = Quantity<Meters>
<category>Unit System</category>
val meters : m:float -> Length
<category index="2">Metric</category>
val rTheta : r:Quantity<'Units> -> theta:Angle -> Vector2D<'Units,'Coordinates>
<summary>
Construct a vector using polar coordinates coordinates given a length and angle
</summary>
Multiple items
module Angle
from Math.Units
<category>Module: Unit System</category>
<summary>
An <c>Angle</c> represents an angle in degrees, radians, or turns. It is stored
as a number of radians.
</summary>
<note>
Angles are sometimes measured in degrees, minutes, and seconds, where 1 minute =
1/60th of a degree and 1 second = 1/60th of a minute.
</note>
<example>
You can construct an angle from your unit scheme. All of the following are equivalent.
<code>
Angle.radians Math.PI
Angle.degrees 180.
Angle.turns 0.5
</code></example>
--------------------
type Angle = Quantity<Radians>
<category>Unit System</category>
val halfPi : Angle
<summary>
π/2.
Alias for <see cref="M:Math.Units.Angle.piOverTwo" />.
</summary>
<category>Constants</category>
val withQuantity : a:Quantity<'Units> -> d:Direction2D<'Coordinates> -> Vector2D<'Units,'Coordinates>
<summary>
Construct a vector with the given length in the given direction.
</summary>
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
val fromAngle : angle:Angle -> Direction2D<'Coordinates>
val vec : Vector2D<Meters,Cartesian>
Multiple items
union case Meters.Meters: Meters
--------------------
type Meters = | Meters
<category>Unit</category>
Vector2D.X: Quantity<Meters>
val x : v:Vector2D<'Units,'Coordinates> -> Quantity<'Units>
Vector2D.Y: Quantity<Meters>
val y : v:Vector2D<'Units,'Coordinates> -> Quantity<'Units>
val magnitude : v:Vector2D<'Units,'Coordinates> -> Quantity<'Units>
val lhs : Vector2D<Meters,Cartesian>
val meters : x:float -> y:float -> Vector2D<Meters,'Coordinates>
val rhs : Vector2D<Meters,Cartesian>
val plus : rhs:Vector2D<'Units,'Coordinates> -> lhs:Vector2D<'Units,'Coordinates> -> Vector2D<'Units,'Coordinates>
<summary>
This function is designed to be used in piping operators.
</summary>
val dot : lhs:Vector2D<'Units,'Coordinates> -> rhs:Vector2D<'Units,'Coordinates> -> Quantity<Squared<'Units>>
val cross : lhs:Vector2D<'Units,'Coordinates> -> rhs:Vector2D<'Units,'Coordinates> -> Quantity<Squared<'Units>>