Usage
# S3 method for class 'Coord1D'
abs(x)
# S3 method for class 'Coord2D'
abs(x)
# S3 method for class 'Coord3D'
abs(x)
Examples
z <- complex(real = 1:4, imaginary = 1:4)
p <- as_coord2d(z)
abs(p) # Euclidean norm
#> [1] 1.414214 2.828427 4.242641 5.656854
# Less efficient ways to calculate same Euclidean norms
sqrt(p * p) # `*` dot product
#> [1] 1.414214 2.828427 4.242641 5.656854
distance2d(p, as_coord2d(0, 0, 0))
#> [1] 1.414214 2.828427 4.242641 5.656854
# In {base} R `abs()` calculates Euclidean norm of complex numbers
all.equal(abs(p), abs(z))
#> [1] TRUE
all.equal(Mod(p), Mod(z))
#> [1] TRUE
p3 <- as_coord3d(x = 1:4, y = 1:4, z = 1:4)
abs(p3)
#> [1] 1.732051 3.464102 5.196152 6.928203