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.799, y:0.758> <x:0.846, y:0.584> <x:0.61, y:0.424>  <x:0.603, y:0.302>
#> [5] <x:0.559, y:0.257>

plot(p)


# 3 dimensions
point(num1, num2, num3)
#> <3D points [5]>
#> [1] <x:0.799, y:0.758, z:0.553> <x:0.846, y:0.584, z:0.137>
#> [3] <x:0.61, y:0.424, z:0.738>  <x:0.603, y:0.302, z:0.904>
#> [5] <x:0.559, y:0.257, z:0.843>

# Standard R vectors are automatically converted to exact_numeric vectors
point(runif(5), runif(5))
#> <2D points [5]>
#> [1] <x:0.64, y:0.349>  <x:0.617, y:0.769> <x:0.122, y:0.794> <x:0.225, y:0.999>
#> [5] <x:0.951, y:0.618>

# Convert points to vectors
as_vec(p)
#> <2D vectors [5]>
#> [1] <x:0.799, y:0.758> <x:0.846, y:0.584> <x:0.61, y:0.424>  <x:0.603, y:0.302>
#> [5] <x:0.559, y:0.257>

# Arithmetic
# Translate by adding vector
p + vec(3, 7)
#> <2D points [5]>
#> [1] <x:3.8, y:7.76>  <x:3.85, y:7.58> <x:3.61, y:7.42> <x:3.6, y:7.3>  
#> [5] <x:3.56, y:7.26>

# Create vector by subtracting points
p[1:2] - p[3:4]
#> <2D vectors [2]>
#> [1] <x:0.188, y:0.335> <x:0.243, y:0.282>

# Sorting etc.
sort(p)
#> <2D points [5]>
#> [1] <x:0.559, y:0.257> <x:0.603, y:0.302> <x:0.61, y:0.424>  <x:0.799, y:0.758>
#> [5] <x:0.846, y:0.584>
min(p)
#> <2D points [1]>
#> [1] <x:0.559, y:0.257>
cummax(p)
#> <2D points [5]>
#> [1] <x:0.799, y:0.758> <x:0.799, y:0.758> <x:0.61, y:0.424>  <x:0.603, y:0.302>
#> [5] <x:0.559, y:0.257>
rank(p)
#> [1] 4 5 3 2 1
p[1:2] < p[3:4]
#> [1] FALSE FALSE