A geometrical vector is somewhat different from the concept of a vector in programming hence the slightly confusing terminology. In geometry a vector is a direction and a magnitude most often defined by a point in space where the direction is defined as the direction from the origin to the point and the magnitude is defined as the distance from the origin to the point.

vec(..., default_dim = 2)

is_vec(x)

as_vec(x)

Arguments

...

Various input. See the Constructor section.

default_dim

The dimensionality when constructing an empty vector

x

A vector of vectors or an object to convert to it

Value

An euclid_vector vector

Constructors

2 dimensional vectors

  • Providing a point will construct vectors pointing to the points from the origin centered.

  • Providing two exact numeric vectors will construct vectors pointing to the point defined by the coordinates given.

  • Providing a ray will construct vectors pointing in the same direction as the ray

3 dimensional vectors

  • Providing a point will construct vectors pointing to the points from the origin centered.

  • Providing three exact numeric vectors will construct vectors pointing to the point defined by the coordinates given.

  • Providing a ray will construct vectors pointing in the same direction as the ray

Examples

# Create vectors from points: v1 <- vec(x = 1:5, y = 4:8) # Vectors can be added and subtracted v1[1] + v1[2]
#> <2D vectors [1]> #> [1] <x:3, y:9>
v1[5] - v1[3]
#> <2D vectors [1]> #> [1] <x:2, y:2>
# You can invert a vector by taking its negative -v1
#> <2D vectors [5]> #> [1] <x:-1, y:-4> <x:-2, y:-5> <x:-3, y:-6> <x:-4, y:-7> <x:-5, y:-8>
# As vectors can be added you can also use sum() and cumsum() sum(v1)
#> <2D vectors [1]> #> [1] <x:15, y:30>
cumsum(v1)
#> <2D vectors [5]> #> [1] <x:1, y:4> <x:3, y:9> <x:6, y:15> <x:10, y:22> <x:15, y:30>
# Multiplying and dividing a vector by a numeric changes its magnitude v1 * 10
#> <2D vectors [5]> #> [1] <x:10, y:40> <x:20, y:50> <x:30, y:60> <x:40, y:70> <x:50, y:80>
v1 / 2.5
#> <2D vectors [5]> #> [1] <x:0.4, y:1.6> <x:0.8, y:2> <x:1.2, y:2.4> <x:1.6, y:2.8> <x:2, y:3.2>
# Multiplying two vectors gives the inner product of the two v1[1:2] * v1[3:4]
#> <exact numerics [2]> #> [1] 27 43
# Vectors can be converted to points, directions and transformation matrices as_point(v1)
#> <2D points [5]> #> [1] <x:1, y:4> <x:2, y:5> <x:3, y:6> <x:4, y:7> <x:5, y:8>
#> <2D directions [5]> #> [1] <dx:1, dy:4> <dx:2, dy:5> <dx:3, dy:6> <dx:4, dy:7> <dx:5, dy:8>
#> <2D affine transformation matrices [5]> #> [1] [<1, 0, 1>/<0, 1, 4>] [<1, 0, 2>/<0, 1, 5>] [<1, 0, 3>/<0, 1, 6>] #> [4] [<1, 0, 4>/<0, 1, 7>] [<1, 0, 5>/<0, 1, 8>]