Skip to contents

This class is an extension (but not a subclass of) point(). It simply attaches a numeric weight to the point that is carried along with it. However, most of the functionality of points are lost with this vector class as all the a math and sorting operations are gone due to ambiguity on whether to operate on the point or the weight. Weighted points can easily be converted to points however.

Usage

weighted_point(..., default_dim = 2)

is_weighted_point(x)

as_weighted_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_w vector

Constructors

2 dimensional weighted points

  • Providing three numeric vector will construct points with those x and y coordinate and a weight.

  • Providing a point and a numeric will construct points with the given weight

3 dimensional weighted points

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

  • Providing a point and a numeric will construct points with the given weight

See also

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

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

Examples

# Construction
wp <- weighted_point(sample(5), sample(5), runif(5))
wp
#> <2D point_ws [5]>
#> [1] <x:5, y:5, w:0.0665> <x:4, y:1, w:0.428>  <x:3, y:3, w:0.0625>
#> [4] <x:2, y:2, w:0.984>  <x:1, y:4, w:0.642> 

# Convert to point
p <- as_point(wp)
p
#> <2D points [5]>
#> [1] <x:5, y:5> <x:4, y:1> <x:3, y:3> <x:2, y:2> <x:1, y:4>

# Construct from point and weight

weighted_point(p, 1:5)
#> <2D point_ws [5]>
#> [1] <x:5, y:5, w:1> <x:4, y:1, w:2> <x:3, y:3, w:3> <x:2, y:2, w:4>
#> [5] <x:1, y:4, w:5>