Skip to contents

Coord3D is an R6::R6Class() object representing three-dimensional points represented by Cartesian Coordinates.

Active bindings

xyzw

A four-column matrix representing the homogeneous coordinates. The first three columns are "x", "y", and "z" coordinates and the fourth column is all ones.

x

A numeric vector of x-coordinates.

y

A numeric vector of y-coordinates.

z

A numeric vector of z-coordinates.

Methods


Coord3D$new()

Usage

Coord3D$new(xyzw)

Arguments

xyzw

A matrix with four columns representing (homogeneous) coordinates. The first three columns represent x, y, and z coordinates and the last column is all ones. Column names should be "x", "y", "z", and "w".


Coord3D$permute()

Usage

Coord3D$permute(permutation = c("xyz", "xzy", "yxz", "yzx", "zyx", "zxy"))

Arguments

permutation

Either "xyz" (no permutation), "xzy" (permute y and z axes), "yxz" (permute x and y axes), "yzx" (x becomes z, y becomes x, z becomes y), "zxy" (x becomes y, y becomes z, z becomes x), "zyx" (permute x and z axes)


Coord3D$print()

Usage

Coord3D$print(n = NULL, ...)

Arguments

n

Number of coordinates to print. If NULL print all of them.

...

Passed to format.default().


Coord3D$project()

Usage

Coord3D$project(
  plane = as_plane3d("xy-plane"),
  ...,
  scale = 0,
  alpha = angle(45, "degrees")
)

Arguments

plane

A Plane3D object of length one representing the plane you wish to reflect across or project to or an object coercible to one using as_plane3d(plane, ...) such as "xy-plane", "xz-plane", or "yz-plane".

...

Passed to project3d().

scale

Oblique projection foreshortening scale factor. A (degenerate) 0 value indicates an orthographic projection. A value of 0.5 is used by a “cabinet projection” while a value of 1.0 is used by a “cavalier projection”.

alpha

Oblique projection angle (the angle the third axis is projected going off at). An angle() object or one coercible to one with as_angle(alpha, ...). Popular angles are 45 degrees, 60 degrees, and arctangent(2) degrees.


Coord3D$reflect()

Usage

Coord3D$reflect(plane = as_plane3d("xy-plane"), ...)

Arguments

plane

A Plane3D object of length one representing the plane you wish to reflect across or project to or an object coercible to one using as_plane3d(plane, ...) such as "xy-plane", "xz-plane", or "yz-plane".

...

Passed to reflect3d().


Coord3D$rotate()

Usage

Coord3D$rotate(axis = as_coord3d("z-axis"), theta = angle(0), ...)

Arguments

axis

A Coord3D class object or one that can coerced to one by as_coord3d(axis, ...). The axis represents the axis to be rotated around.

theta

An angle() object of length one or an object coercible to one by as_angle(theta, ...).

...

Passed to rotate3d().


Coord3D$scale()

Usage

Coord3D$scale(x_scale = 1, y_scale = x_scale, z_scale = x_scale)

Arguments

x_scale

Scaling factor to apply to x coordinates

y_scale

Scaling factor to apply to y coordinates

z_scale

Scaling factor to apply to z coordinates


Coord3D$shear()

Usage

Coord3D$shear(
  xy_shear = 0,
  xz_shear = 0,
  yx_shear = 0,
  yz_shear = 0,
  zx_shear = 0,
  zy_shear = 0
)

Arguments

xy_shear

Shear factor: x = x + xy_shear * y + xz_shear * z

xz_shear

Shear factor: x = x + xy_shear * y + xz_shear * z

yx_shear

Shear factor: y = yx_shear * x + y + yz_shear * z

yz_shear

Shear factor: y = yx_shear * x + y + yz_shear * z

zx_shear

Shear factor: z = zx_shear * x + zy_shear * y + z

zy_shear

Shear factor: z = zx_shear * x + zy_shear * y + z


Coord3D$translate()

Usage

Coord3D$translate(x = as_coord3d(0, 0, 0), ...)

Arguments

x

A Coord3D object of length one or an object coercible to one by as_coord3d(x, ...).

...

Passed to as_coord3d(x, ...) if x is not a Coord3D object


Coord3D$transform()

Usage

Coord3D$transform(mat = transform3d())

Arguments

mat

A 4x4 matrix representing a post-multiplied affine transformation matrix. The last column must be equal to c(0, 0, 0, 1). If the last row is c(0, 0, 0, 1) you may need to transpose it to convert it from a pre-multiplied affine transformation matrix to a post-multiplied one. If a 3x3 matrix (such as a 3x3 post-multiplied 3D rotation matrix) we'll quietly add a final column/row equal to c(0, 0, 0, 1).


Coord3D$clone()

The objects of this class are cloneable with this method.

Usage

Coord3D$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

p <- as_coord3d(x = rnorm(100, 2), y = rnorm(100, 2), z = rnorm(100, 2))
print(p, n = 10)
#> <Coord3D[100]>
#>               x         y         z w
#>  [1,] 1.6438756 3.7361110 1.2884759 1
#>  [2,] 0.9355358 1.1547522 2.6621788 1
#>  [3,] 3.0771165 1.0384285 2.2911302 1
#>  [4,] 3.1815756 3.0174911 2.1979580 1
#>  [5,] 2.1983921 0.5039463 0.7964339 1
#>  [6,] 1.5995948 0.8151813 1.9601830 1
#>  [7,] 2.6161543 2.6302344 2.6869825 1
#>  [8,] 3.9741567 4.1012525 2.7052670 1
#>  [9,] 3.8846623 1.3862632 2.9914417 1
#> [10,] 0.4113795 0.3653617 3.1442490 1
pc <- mean(p) # Centroid
# method chained affine transformation matrices are auto-pre-multiplied
p$
  translate(-pc)$
  reflect("xy-plane")$
  rotate("z-axis", degrees(90))$
  print(n = 10)
#> <Coord3D[100]>
#>                x           y           z w
#>  [1,] -1.9126698 -0.54472328  0.65979008 1
#>  [2,]  0.6686890 -1.25306307 -0.71391285 1
#>  [3,]  0.7850127  0.88851767 -0.34286428 1
#>  [4,] -1.1940498  0.99297670 -0.24969205 1
#>  [5,]  1.3194950  0.00979323  1.15183205 1
#>  [6,]  1.0082599 -0.58900411 -0.01191701 1
#>  [7,] -0.8067932  0.42755542 -0.73871652 1
#>  [8,] -2.2778113  1.78555788 -0.75700106 1
#>  [9,]  0.4371780  1.69606346 -1.04317573 1
#> [10,]  1.4580795 -1.77721941 -1.19598303 1