Skip to contents

Points are the fundamental unit in geometry, from which other geometric primitives can be constructed. Points support less than and greater than operations which are handled lexicographically. This means that point vectors can also be sorted and ranked. Subtracking a point from a point gives a vector. Adding and subtracting a vector to a point translates the point by the vector.

Usage

point(..., default_dim = 2)

is_point(x)

as_point(x)

Arguments

...

Various input. See the Constructor section.

default_dim

The dimensionality when constructing an empty vector

x

A point vector or an object to convert to it

Value

a euclid_point vector

Constructors

2 dimensional points

  • Providing two numeric vector will construct points with those x and y coordinate.

  • Providing a vector will construct a point at the location the vector points to.

  • Providing a weighted point vector will create a points at the same locations without weights.

3 dimensional points

  • Providing three numeric vector will construct points with those x, y, and z coordinate.

  • Providing a vector will construct a point at the location the vector points to.

  • Providing a weighted point vector will create a points at the same locations without weights.

See also

Other Geometries: circle(), direction(), iso_cube(), iso_rect(), line(), plane(), ray(), segment(), sphere(), tetrahedron(), triangle(), vec(), weighted_point()

Other Locations: barycenter(), bisector(), centroid(), circumcenter(), equidistant_line(), radical(), weighted_point()

Examples

num1 <- exact_numeric(runif(5))
num2 <- exact_numeric(runif(5))
num3 <- exact_numeric(runif(5))

# 2 dimensions
p <- point(num1, num2)
p
#> <2D points [5]>
#> [1] <x:0.992, y:0.218> <x:0.789, y:0.869> <x:0.17, y:0.96>   <x:0.329, y:0.485>
#> [5] <x:0.531, y:0.198>

plot(p)


# 3 dimensions
point(num1, num2, num3)
#> <3D points [5]>
#> [1] <x:0.992, y:0.218, z:0.345> <x:0.789, y:0.869, z:0.266>
#> [3] <x:0.17, y:0.96, z:0.547>   <x:0.329, y:0.485, z:0.499>
#> [5] <x:0.531, y:0.198, z:0.803>

# Standard R vectors are automatically converted to exact_numeric vectors
point(runif(5), runif(5))
#> <2D points [5]>
#> [1] <x:0.36, y:0.239>  <x:0.579, y:0.323> <x:0.14, y:0.897>  <x:0.828, y:0.918>
#> [5] <x:0.154, y:0.843>

# Convert points to vectors
as_vec(p)
#> <2D vectors [5]>
#> [1] <x:0.992, y:0.218> <x:0.789, y:0.869> <x:0.17, y:0.96>   <x:0.329, y:0.485>
#> [5] <x:0.531, y:0.198>

# Arithmetic
# Translate by adding vector
p + vec(3, 7)
#> <2D points [5]>
#> [1] <x:3.99, y:7.22> <x:3.79, y:7.87> <x:3.17, y:7.96> <x:3.33, y:7.49>
#> [5] <x:3.53, y:7.2> 

# Create vector by subtracting points
p[1:2] - p[3:4]
#> <2D vectors [2]>
#> [1] <x:0.822, y:-0.742> <x:0.46, y:0.383>  

# Sorting etc.
sort(p)
#> <2D points [5]>
#> [1] <x:0.17, y:0.96>   <x:0.329, y:0.485> <x:0.531, y:0.198> <x:0.789, y:0.869>
#> [5] <x:0.992, y:0.218>
min(p)
#> <2D points [1]>
#> [1] <x:0.17, y:0.96>
cummax(p)
#> <2D points [5]>
#> [1] <x:0.992, y:0.218> <x:0.789, y:0.869> <x:0.17, y:0.96>   <x:0.17, y:0.96>  
#> [5] <x:0.17, y:0.96>  
rank(p)
#> [1] 5 4 1 2 3
p[1:2] < p[3:4]
#> [1] FALSE FALSE