Title: | A Finer Way to Render 3D Illustrated Objects in 'grid' Using Affine Transformations |
---|---|
Description: | Dilate, permute, project, reflect, rotate, shear, and translate 2D and 3D points. Supports parallel projections including oblique projections such as the cabinet projection as well as axonometric projections such as the isometric projection. Use 'grid's "affine transformation" feature to render illustrated flat surfaces. |
Authors: | Trevor L. Davis [aut, cre] |
Maintainer: | Trevor L. Davis <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1 |
Built: | 2024-11-09 05:54:08 UTC |
Source: | https://github.com/trevorld/affiner |
Dilate, permute, project, reflect, rotate, shear, and translate 2D and 3D points. Supports parallel projections including oblique projections such as the cabinet projection as well as axonometric projections such as the isometric projection. Use 'grid's "affine transformation" feature to render illustrated flat surfaces.
The following affiner function arguments may be set globally via base::options()
:
The default for the unit
argument used by angle()
and as_angle()
.
The default for this option is "degrees".
The default for the unit
argument used by affine_settings()
.
The default for this option is "inches".
The following cli
options may also be of interest:
Whether UTF-8 character support should be assumed.
Along with l10n_info()
used to determine the default of the
use_unicode
argument of format.angle()
and print.angle()
.
Maintainer: Trevor L. Davis [email protected] (ORCID)
Useful links:
abs()
computes the Euclidean norm for Coord2D class objects and Coord3D class objects.
## S3 method for class 'Coord1D' abs(x) ## S3 method for class 'Coord2D' abs(x) ## S3 method for class 'Coord3D' abs(x)
## S3 method for class 'Coord1D' abs(x) ## S3 method for class 'Coord2D' abs(x) ## S3 method for class 'Coord3D' abs(x)
x |
A numeric vector
z <- complex(real = 1:4, imaginary = 1:4) p <- as_coord2d(z) abs(p) # Euclidean norm # Less efficient ways to calculate same Euclidean norms sqrt(p * p) # `*` dot product distance2d(p, as_coord2d(0, 0, 0)) # In {base} R `abs()` calculates Euclidean norm of complex numbers all.equal(abs(p), abs(z)) all.equal(Mod(p), Mod(z)) p3 <- as_coord3d(x = 1:4, y = 1:4, z = 1:4) abs(p3)
z <- complex(real = 1:4, imaginary = 1:4) p <- as_coord2d(z) abs(p) # Euclidean norm # Less efficient ways to calculate same Euclidean norms sqrt(p * p) # `*` dot product distance2d(p, as_coord2d(0, 0, 0)) # In {base} R `abs()` calculates Euclidean norm of complex numbers all.equal(abs(p), abs(z)) all.equal(Mod(p), Mod(z)) p3 <- as_coord3d(x = 1:4, y = 1:4, z = 1:4) abs(p3)
grid
affine transformation feature viewports and transformation functionsaffine_settings()
computes grid
group affine transformation feature viewport and transformation
function settings given the (x,y) coordinates of the corners of the
affine transformed "viewport" one wishes to draw in.
affine_settings( xy = data.frame(x = c(0, 0, 1, 1), y = c(1, 0, 0, 1)), unit = getOption("affiner_grid_unit", "inches") )
affine_settings( xy = data.frame(x = c(0, 0, 1, 1), y = c(1, 0, 0, 1)), unit = getOption("affiner_grid_unit", "inches") )
xy |
An R object with named elements |
unit |
Which |
A named list with the following group affine transformation feature viewport and functions settings:
An affine transformation function to pass to affineGrob()
or useGrob()
.
If getRversion()
is less than "4.2.0"
will instead be NULL
.
A grid::viewport()
object to pass to affineGrob()
or useGrob()
.
x-axis sx factor
whether the affine transformed "viewport" is "flipped" horizontally
x-coordinate for viewport
y-coordinate for viewport
Width of viewport
Height of viewport
Default grid::unit()
for viewport
angle for viewport
To avoid taking a dependency on affiner
you may copy the source of affine_settings()
into your own package under the permissive Unlicense. Either use
usethis::use_standalone("trevorld/affiner", "standalone-affine-settings.r")
or
copy the file standalone-affine-settings.r
into your R
directory and add grid
to the Imports
of your DESCRIPTION
file.
Intended for use with affineGrob()
and grid::useGrob()
.
See https://www.stat.auckland.ac.nz/~paul/Reports/GraphicsEngine/groups/groups.html
for more information about the group affine transformation feature.
if (require("grid")) { grob <- grobTree(rectGrob(gp = gpar(fill = "blue", col = NA)), circleGrob(gp=gpar(fill="yellow", col = NA)), textGrob("RSTATS", gp=gpar(fontsize=32))) grid.newpage() pushViewport(viewport(width=unit(4, "in"), height=unit(2, "in"))) grid.draw(grob) popViewport() } if (require("grid") && getRversion() >= "4.2.0" && isTRUE(dev.capabilities()$transformations)) { # Only works if active graphics device supports affine transformations # such as `png(type="cairo")` on R 4.2+ vp_define <- viewport(width=unit(2, "in"), height=unit(2, "in")) settings <- affine_settings(xy = list(x = c(1/3, 0/3, 2/3, 3/3), y = c(2/3, 1/3, 1/3, 2/3)), unit = "snpc") affine <- affineGrob(grob, vp_define=vp_define, transform = settings$transform, vp_use = settings$vp) grid.newpage() grid.draw(affine) } if (require("grid") && getRversion() >= "4.2.0" && isTRUE(dev.capabilities()$transformations)) { # Only works if active graphics device supports affine transformations # such as `png(type="cairo")` on R 4.2+ settings <- affine_settings(xy = list(x = c(3/3, 2/3, 0/3, 1/3), y = c(2/3, 1/3, 1/3, 2/3)), unit = "snpc") affine <- affineGrob(grob, vp_define=vp_define, transform = settings$transform, vp_use = settings$vp) grid.newpage() grid.draw(affine) }
if (require("grid")) { grob <- grobTree(rectGrob(gp = gpar(fill = "blue", col = NA)), circleGrob(gp=gpar(fill="yellow", col = NA)), textGrob("RSTATS", gp=gpar(fontsize=32))) grid.newpage() pushViewport(viewport(width=unit(4, "in"), height=unit(2, "in"))) grid.draw(grob) popViewport() } if (require("grid") && getRversion() >= "4.2.0" && isTRUE(dev.capabilities()$transformations)) { # Only works if active graphics device supports affine transformations # such as `png(type="cairo")` on R 4.2+ vp_define <- viewport(width=unit(2, "in"), height=unit(2, "in")) settings <- affine_settings(xy = list(x = c(1/3, 0/3, 2/3, 3/3), y = c(2/3, 1/3, 1/3, 2/3)), unit = "snpc") affine <- affineGrob(grob, vp_define=vp_define, transform = settings$transform, vp_use = settings$vp) grid.newpage() grid.draw(affine) } if (require("grid") && getRversion() >= "4.2.0" && isTRUE(dev.capabilities()$transformations)) { # Only works if active graphics device supports affine transformations # such as `png(type="cairo")` on R 4.2+ settings <- affine_settings(xy = list(x = c(3/3, 2/3, 0/3, 1/3), y = c(2/3, 1/3, 1/3, 2/3)), unit = "snpc") affine <- affineGrob(grob, vp_define=vp_define, transform = settings$transform, vp_use = settings$vp) grid.newpage() grid.draw(affine) }
affineGrob()
is a grid grob function to facilitate
using the group affine transformation features introduced in R 4.2.
affineGrob( grob, vp_define = NULL, transform = NULL, vp_use = NULL, name = NULL, gp = grid::gpar(), vp = NULL ) grid.affine(...)
affineGrob( grob, vp_define = NULL, transform = NULL, vp_use = NULL, name = NULL, gp = grid::gpar(), vp = NULL ) grid.affine(...)
grob |
A grid grob to perform affine transformations on. Passed to |
vp_define |
|
transform |
An affine transformation function.
If |
vp_use |
|
name |
A character identifier (for grid). |
gp |
A |
vp |
A |
... |
Passed to |
A grid::gTree()
(grob) object of class "affine".
As a side effect grid.affine()
draws to the active graphics device.
See affine_settings()
for computing good transform
and vp_use
settings.
See https://www.stat.auckland.ac.nz/~paul/Reports/GraphicsEngine/groups/groups.html
for more information about the group affine transformation feature.
See isocubeGrob()
which wraps this function to render isometric cubes.
if (require("grid")) { grob <- grobTree(rectGrob(gp = gpar(fill = "blue", col = NA)), circleGrob(gp=gpar(fill="yellow", col = NA)), textGrob("RSTATS", gp=gpar(fontsize=32))) grid.newpage() pushViewport(viewport(width=unit(4, "in"), height=unit(2, "in"))) grid.draw(grob) popViewport() } if (require("grid") && getRversion() >= "4.2.0" && isTRUE(dev.capabilities()$transformations)) { # Only works if active graphics device supports affine transformations # such as `png(type="cairo")` on R 4.2+ vp_define <- viewport(width=unit(2, "in"), height=unit(2, "in")) affine <- affineGrob(grob, vp_define=vp_define) grid.newpage() pushViewport(viewport(width=unit(4, "in"), height=unit(2, "in"))) grid.draw(affine) popViewport() } if (require("grid") && getRversion() >= "4.2.0" && isTRUE(dev.capabilities()$transformations)) { # Only works if active graphics device supports affine transformations # such as `png(type="cairo")` on R 4.2+ settings <- affine_settings(xy = list(x = c(3/3, 2/3, 0/3, 1/3), y = c(2/3, 1/3, 1/3, 2/3)), unit = "snpc") affine <- affineGrob(grob, vp_define = vp_define, transform = settings$transform, vp_use = settings$vp) grid.newpage() grid.draw(affine) }
if (require("grid")) { grob <- grobTree(rectGrob(gp = gpar(fill = "blue", col = NA)), circleGrob(gp=gpar(fill="yellow", col = NA)), textGrob("RSTATS", gp=gpar(fontsize=32))) grid.newpage() pushViewport(viewport(width=unit(4, "in"), height=unit(2, "in"))) grid.draw(grob) popViewport() } if (require("grid") && getRversion() >= "4.2.0" && isTRUE(dev.capabilities()$transformations)) { # Only works if active graphics device supports affine transformations # such as `png(type="cairo")` on R 4.2+ vp_define <- viewport(width=unit(2, "in"), height=unit(2, "in")) affine <- affineGrob(grob, vp_define=vp_define) grid.newpage() pushViewport(viewport(width=unit(4, "in"), height=unit(2, "in"))) grid.draw(affine) popViewport() } if (require("grid") && getRversion() >= "4.2.0" && isTRUE(dev.capabilities()$transformations)) { # Only works if active graphics device supports affine transformations # such as `png(type="cairo")` on R 4.2+ settings <- affine_settings(xy = list(x = c(3/3, 2/3, 0/3, 1/3), y = c(2/3, 1/3, 1/3, 2/3)), unit = "snpc") affine <- affineGrob(grob, vp_define = vp_define, transform = settings$transform, vp_use = settings$vp) grid.newpage() grid.draw(affine) }
affiner_options()
returns the affiner
package's global options.
affiner_options(..., default = FALSE)
affiner_options(..., default = FALSE)
... |
|
default |
If |
A list of option values.
Note this function does not set option values itself but
this list can be passed to options()
, withr::local_options()
, or withr::with_options()
.
affiner for a high-level description of relevant global options.
affiner_options() affiner_options(default = TRUE) affiner_options(affiner_angular_unit = "pi-radians")
affiner_options() affiner_options(default = TRUE) affiner_options(affiner_angular_unit = "pi-radians")
angle()
creates angle vectors with user specified angular unit.
around as_angle()
for those angular units.
angle(x = numeric(), unit = getOption("affiner_angular_unit", "degrees")) degrees(x) gradians(x) pi_radians(x) radians(x) turns(x)
angle(x = numeric(), unit = getOption("affiner_angular_unit", "degrees")) degrees(x) gradians(x) pi_radians(x) radians(x) turns(x)
x |
An angle vector or an object to convert to it (such as a numeric vector) |
unit |
A string of the desired angular unit. Supports the following strings
(note we ignore any punctuation and space characters as well as any trailing
|
A numeric vector of class "angle". Its "unit" attribute is a standardized string of the specified angular unit.
as_angle()
, angular_unit()
, and angle-methods.
https://en.wikipedia.org/wiki/Angle#Units for more information about angular units.
# Different representations of the "same" angle angle(180, "degrees") angle(pi, "radians") angle(0.5, "turns") angle(200, "gradians") pi_radians(1) a1 <- angle(180, "degrees") angular_unit(a1) is_angle(a1) as.numeric(a1, "radians") cos(a1) a2 <- as_angle(a1, "radians") angular_unit(a2) is_congruent(a1, a2)
# Different representations of the "same" angle angle(180, "degrees") angle(pi, "radians") angle(0.5, "turns") angle(200, "gradians") pi_radians(1) a1 <- angle(180, "degrees") angular_unit(a1) is_angle(a1) as.numeric(a1, "radians") cos(a1) a2 <- as_angle(a1, "radians") angular_unit(a2) is_congruent(a1, a2)
We implemented methods for several base generics for the angle()
vectors.
## S3 method for class 'angle' as.double(x, unit = angular_unit(x), ...) ## S3 method for class 'angle' as.complex(x, modulus = 1, ...) ## S3 method for class 'angle' format(x, unit = angular_unit(x), ..., use_unicode = is_utf8_output()) ## S3 method for class 'angle' print(x, unit = angular_unit(x), ..., use_unicode = is_utf8_output()) ## S3 method for class 'angle' abs(x)
## S3 method for class 'angle' as.double(x, unit = angular_unit(x), ...) ## S3 method for class 'angle' as.complex(x, modulus = 1, ...) ## S3 method for class 'angle' format(x, unit = angular_unit(x), ..., use_unicode = is_utf8_output()) ## S3 method for class 'angle' print(x, unit = angular_unit(x), ..., use_unicode = is_utf8_output()) ## S3 method for class 'angle' abs(x)
x |
|
unit |
A string of the desired angular unit. Supports the following strings
(note we ignore any punctuation and space characters as well as any trailing
|
... |
Passed to |
modulus |
Numeric vector representing the complex numbers' modulus |
use_unicode |
If |
Mathematical Ops (in particular +
and -
)
for two angle vectors will (if necessary)
set the second vector's angular_unit()
to match the first.
as.numeric()
takes a unit
argument which can be used to convert angles into other angular units
e.g. angle(x, "degrees") |> as.numeric("radians")
to cast a numeric vector x
from degrees to radians.
abs()
will calculate the angle modulo full turns.
Use is_congruent()
to test if two angles are congruent instead of ==
or all.equal()
.
Not all implemented methods are documented here and since angle()
is a
numeric()
class many other S3 generics
besides the explicitly implemented ones should also work with it.
Typical values as usually returned by these base generics.
# Two "congruent" angles a1 <- angle(180, "degrees") a2 <- angle(pi, "radians") print(a1) print(a1, unit = "radians") print(a1, unit = "pi-radians") cos(a1) sin(a1) tan(a1) # mathematical operations will coerce second `angle()` object to # same `angular_unit()` as the first one a1 + a2 a1 - a2 as.numeric(a1) as.numeric(a1, "radians") as.numeric(a1, "turns") # Use `is_congruent()` to check if two angles are "congruent" a1 == a2 isTRUE(all.equal(a1, a2)) is_congruent(a1, a2) is_congruent(a1, a2, mod_turns = FALSE) a3 <- angle(-180, "degrees") # Only congruent modulus full turns a1 == a3 isTRUE(all.equal(a1, a2)) is_congruent(a1, a3) is_congruent(a1, a3, mod_turns = FALSE)
# Two "congruent" angles a1 <- angle(180, "degrees") a2 <- angle(pi, "radians") print(a1) print(a1, unit = "radians") print(a1, unit = "pi-radians") cos(a1) sin(a1) tan(a1) # mathematical operations will coerce second `angle()` object to # same `angular_unit()` as the first one a1 + a2 a1 - a2 as.numeric(a1) as.numeric(a1, "radians") as.numeric(a1, "turns") # Use `is_congruent()` to check if two angles are "congruent" a1 == a2 isTRUE(all.equal(a1, a2)) is_congruent(a1, a2) is_congruent(a1, a2, mod_turns = FALSE) a3 <- angle(-180, "degrees") # Only congruent modulus full turns a1 == a3 isTRUE(all.equal(a1, a2)) is_congruent(a1, a3) is_congruent(a1, a3, mod_turns = FALSE)
angular_unit()
gets/sets the angular unit of angle()
vectors.
angular_unit(x) angular_unit(x) <- value
angular_unit(x) angular_unit(x) <- value
x |
An |
value |
A string of the desired angular unit. See |
angular_unit()
returns a string of x
's angular unit.
a <- angle(seq(0, 360, by = 90), "degrees") angular_unit(a) print(a) angular_unit(a) <- "turns" angular_unit(a) print(a)
a <- angle(seq(0, 360, by = 90), "degrees") angular_unit(a) print(a) angular_unit(a) <- "turns" angular_unit(a) print(a)
as_angle()
casts to an angle()
vector
as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...) ## S3 method for class 'angle' as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...) ## S3 method for class 'character' as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...) ## S3 method for class 'complex' as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...) ## S3 method for class 'Coord2D' as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...) ## S3 method for class 'Coord3D' as_angle( x, unit = getOption("affiner_angular_unit", "degrees"), type = c("azimuth", "inclination"), ... ) ## S3 method for class 'Line2D' as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...) ## S3 method for class 'Plane3D' as_angle( x, unit = getOption("affiner_angular_unit", "degrees"), type = c("azimuth", "inclination"), ... ) ## S3 method for class 'numeric' as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...)
as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...) ## S3 method for class 'angle' as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...) ## S3 method for class 'character' as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...) ## S3 method for class 'complex' as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...) ## S3 method for class 'Coord2D' as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...) ## S3 method for class 'Coord3D' as_angle( x, unit = getOption("affiner_angular_unit", "degrees"), type = c("azimuth", "inclination"), ... ) ## S3 method for class 'Line2D' as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...) ## S3 method for class 'Plane3D' as_angle( x, unit = getOption("affiner_angular_unit", "degrees"), type = c("azimuth", "inclination"), ... ) ## S3 method for class 'numeric' as_angle(x, unit = getOption("affiner_angular_unit", "degrees"), ...)
x |
An R object to convert to a |
unit |
A string of the desired angular unit. Supports the following strings
(note we ignore any punctuation and space characters as well as any trailing
|
... |
Further arguments passed to or from other methods |
type |
Use "azimuth" to calculate the azimuthal angle and "inclination" to calculate the inclination angle aka polar angle. |
An angle()
vector
as_angle(angle(pi, "radians"), "pi-radians") as_angle(complex(real = 0, imaginary = 1), "degrees") as_angle(as_coord2d(x = 0, y = 1), "turns") as_angle(200, "gradians")
as_angle(angle(pi, "radians"), "pi-radians") as_angle(complex(real = 0, imaginary = 1), "degrees") as_angle(as_coord2d(x = 0, y = 1), "turns") as_angle(200, "gradians")
as_coord1d()
casts to a Coord1D class object
as_coord1d(x, ...) ## S3 method for class 'character' as_coord1d(x, ...) ## S3 method for class 'Coord2D' as_coord1d( x, permutation = c("xy", "yx"), ..., line = as_line2d("x-axis"), scale = 0 ) ## S3 method for class 'data.frame' as_coord1d(x, ...) ## S3 method for class 'list' as_coord1d(x, ...) ## S3 method for class 'matrix' as_coord1d(x, ...) ## S3 method for class 'numeric' as_coord1d(x, ...) ## S3 method for class 'Coord1D' as_coord1d(x, ...) ## S3 method for class 'Point1D' as_coord1d(x, ...)
as_coord1d(x, ...) ## S3 method for class 'character' as_coord1d(x, ...) ## S3 method for class 'Coord2D' as_coord1d( x, permutation = c("xy", "yx"), ..., line = as_line2d("x-axis"), scale = 0 ) ## S3 method for class 'data.frame' as_coord1d(x, ...) ## S3 method for class 'list' as_coord1d(x, ...) ## S3 method for class 'matrix' as_coord1d(x, ...) ## S3 method for class 'numeric' as_coord1d(x, ...) ## S3 method for class 'Coord1D' as_coord1d(x, ...) ## S3 method for class 'Point1D' as_coord1d(x, ...)
x |
An object that can be cast to a Coord1D class object such as a numeric vector of x-coordinates. |
... |
Further arguments passed to or from other methods |
permutation |
Either "xy" (no permutation) or "yx" (permute x and y axes) |
line |
A Line2D object of length one representing the line
you with to reflect across or project to or an object coercible to one by |
scale |
Oblique projection scale factor.
A degenerate |
A Coord1D class object
as_coord1d(x = rnorm(10))
as_coord1d(x = rnorm(10))
as_coord2d()
casts to a Coord2D class object
as_coord2d(x, ...) ## S3 method for class 'angle' as_coord2d(x, radius = 1, ...) ## S3 method for class 'character' as_coord2d(x, ...) ## S3 method for class 'complex' as_coord2d(x, ...) ## S3 method for class 'Coord3D' as_coord2d( x, permutation = c("xyz", "xzy", "yxz", "yzx", "zyx", "zxy"), ..., plane = as_plane3d("xy-plane"), scale = 0, alpha = angle(45, "degrees") ) ## S3 method for class 'data.frame' as_coord2d(x, ...) ## S3 method for class 'list' as_coord2d(x, ...) ## S3 method for class 'matrix' as_coord2d(x, ...) ## S3 method for class 'numeric' as_coord2d(x, y = rep_len(0, length(x)), ...) ## S3 method for class 'Coord2D' as_coord2d(x, ...)
as_coord2d(x, ...) ## S3 method for class 'angle' as_coord2d(x, radius = 1, ...) ## S3 method for class 'character' as_coord2d(x, ...) ## S3 method for class 'complex' as_coord2d(x, ...) ## S3 method for class 'Coord3D' as_coord2d( x, permutation = c("xyz", "xzy", "yxz", "yzx", "zyx", "zxy"), ..., plane = as_plane3d("xy-plane"), scale = 0, alpha = angle(45, "degrees") ) ## S3 method for class 'data.frame' as_coord2d(x, ...) ## S3 method for class 'list' as_coord2d(x, ...) ## S3 method for class 'matrix' as_coord2d(x, ...) ## S3 method for class 'numeric' as_coord2d(x, y = rep_len(0, length(x)), ...) ## S3 method for class 'Coord2D' as_coord2d(x, ...)
x |
An object that can be cast to a Coord2D class object such as a matrix or data frame of coordinates. |
... |
Further arguments passed to or from other methods |
radius |
A numeric vector of radial distances. |
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). This permutation is applied before the (oblique) projection. |
plane |
A Plane3D class object representing the plane
you wish to project to or an object coercible to one using |
scale |
Oblique projection foreshortening scale factor.
A (degenerate) |
alpha |
Oblique projection angle (the angle the third axis is projected going off at).
An |
y |
Numeric vector of y-coordinates to be used. |
A Coord2D class object
df <- data.frame(x = sample.int(10, 3), y = sample.int(10, 3)) as_coord2d(df) as_coord2d(complex(real = 3, imaginary = 2)) as_coord2d(angle(90, "degrees"), radius = 2) as_coord2d(as_coord3d(1, 2, 2), alpha = degrees(90), scale = 0.5)
df <- data.frame(x = sample.int(10, 3), y = sample.int(10, 3)) as_coord2d(df) as_coord2d(complex(real = 3, imaginary = 2)) as_coord2d(angle(90, "degrees"), radius = 2) as_coord2d(as_coord3d(1, 2, 2), alpha = degrees(90), scale = 0.5)
as_coord3d()
casts to a Coord3D class object
as_coord3d(x, ...) ## S3 method for class 'angle' as_coord3d(x, radius = 1, inclination = NULL, z = NULL, ...) ## S3 method for class 'character' as_coord3d(x, ...) ## S3 method for class 'data.frame' as_coord3d(x, ..., z = NULL) ## S3 method for class 'list' as_coord3d(x, ..., z = NULL) ## S3 method for class 'matrix' as_coord3d(x, ...) ## S3 method for class 'numeric' as_coord3d(x, y = rep_len(0, length(x)), z = rep_len(0, length(x)), ...) ## S3 method for class 'Coord3D' as_coord3d(x, ...) ## S3 method for class 'Coord2D' as_coord3d(x, z = rep_len(0, length(x)), ...)
as_coord3d(x, ...) ## S3 method for class 'angle' as_coord3d(x, radius = 1, inclination = NULL, z = NULL, ...) ## S3 method for class 'character' as_coord3d(x, ...) ## S3 method for class 'data.frame' as_coord3d(x, ..., z = NULL) ## S3 method for class 'list' as_coord3d(x, ..., z = NULL) ## S3 method for class 'matrix' as_coord3d(x, ...) ## S3 method for class 'numeric' as_coord3d(x, y = rep_len(0, length(x)), z = rep_len(0, length(x)), ...) ## S3 method for class 'Coord3D' as_coord3d(x, ...) ## S3 method for class 'Coord2D' as_coord3d(x, z = rep_len(0, length(x)), ...)
x |
An object that can be cast to a Coord3D class object such as a matrix or data frame of coordinates. |
... |
Further arguments passed to or from other methods |
radius |
A numeric vector. If |
inclination |
Spherical coordinates inclination angle aka polar angle.
|
z |
Numeric vector of z-coordinates to be used |
y |
Numeric vector of y-coordinates to be used
if |
A Coord3D class object
as_coord3d(x = 1, y = 2, z = 3) df <- data.frame(x = sample.int(10, 3), y = sample.int(10, 3), z = sample.int(10, 3)) as_coord3d(df) # Cylindrical coordinates as_coord3d(degrees(90), z = 1, radius = 1) # Spherical coordinates as_coord3d(degrees(90), inclination = degrees(90), radius = 1)
as_coord3d(x = 1, y = 2, z = 3) df <- data.frame(x = sample.int(10, 3), y = sample.int(10, 3), z = sample.int(10, 3)) as_coord3d(df) # Cylindrical coordinates as_coord3d(degrees(90), z = 1, radius = 1) # Spherical coordinates as_coord3d(degrees(90), inclination = degrees(90), radius = 1)
as_line2d()
casts to a Line2D object.
as_line2d(...) ## S3 method for class 'numeric' as_line2d(a, b, c, ...) ## S3 method for class 'angle' as_line2d(theta, p1 = as_coord2d("origin"), ...) ## S3 method for class 'character' as_line2d(x, ...) ## S3 method for class 'Coord2D' as_line2d(normal, p1 = as_coord3d("origin"), p2, ...) ## S3 method for class 'Line2D' as_line2d(line, ...) ## S3 method for class 'Point1D' as_line2d(point, b = 0, ...)
as_line2d(...) ## S3 method for class 'numeric' as_line2d(a, b, c, ...) ## S3 method for class 'angle' as_line2d(theta, p1 = as_coord2d("origin"), ...) ## S3 method for class 'character' as_line2d(x, ...) ## S3 method for class 'Coord2D' as_line2d(normal, p1 = as_coord3d("origin"), p2, ...) ## S3 method for class 'Line2D' as_line2d(line, ...) ## S3 method for class 'Point1D' as_line2d(point, b = 0, ...)
... |
Passed to other function such as |
a , b , c
|
Numeric vectors that parameterize the line via the equation |
theta |
Angle of the line represented by an |
p1 |
Point on the line represented by a Coord2D class object. |
x |
A (character) vector to be cast to a Line2D object |
normal |
Normal vector to the line represented by a Coord2D class object. |
p2 |
Another point on the line represented by a Coord2D class object. |
line |
A Line2D object |
point |
A Point1D object |
p1 <- as_coord2d(x = 5, y = 10) p2 <- as_coord2d(x = 7, y = 12) theta <- degrees(45) as_line2d(theta, p1) as_line2d(p1, p2)
p1 <- as_coord2d(x = 5, y = 10) p2 <- as_coord2d(x = 7, y = 12) theta <- degrees(45) as_line2d(theta, p1) as_line2d(p1, p2)
as_plane3d()
casts to a Plane3D object.
as_plane3d(...) ## S3 method for class 'numeric' as_plane3d(a, b, c, d, ...) ## S3 method for class 'character' as_plane3d(x, ...) ## S3 method for class 'Coord3D' as_plane3d(normal, p1 = as_coord3d("origin"), p2, p3, ...) ## S3 method for class 'Plane3D' as_plane3d(plane, ...) ## S3 method for class 'Point1D' as_plane3d(point, b = 0, c = 0, ...) ## S3 method for class 'Line2D' as_plane3d(line, c = 0, ...)
as_plane3d(...) ## S3 method for class 'numeric' as_plane3d(a, b, c, d, ...) ## S3 method for class 'character' as_plane3d(x, ...) ## S3 method for class 'Coord3D' as_plane3d(normal, p1 = as_coord3d("origin"), p2, p3, ...) ## S3 method for class 'Plane3D' as_plane3d(plane, ...) ## S3 method for class 'Point1D' as_plane3d(point, b = 0, c = 0, ...) ## S3 method for class 'Line2D' as_plane3d(line, c = 0, ...)
... |
Passed to other function such as |
a , b , c , d
|
Numeric vectors that parameterize the plane via the equation |
x |
A (character) vector to be cast to a Plane3D object |
normal |
Normal vector to the plane represented by a Coord3D class object. |
p1 |
Point on the plane represented by a Coord3D class object. |
p2 , p3
|
Points on the plane represented by Coord3D class objects. |
plane |
A Plane3D object |
point |
A Point1D object |
line |
A Line2D object |
as_point1d()
casts to a Point1D object.
as_point1d(...) ## S3 method for class 'numeric' as_point1d(a, b, ...) ## S3 method for class 'character' as_point1d(x, ...) ## S3 method for class 'Coord1D' as_point1d(normal, ...) ## S3 method for class 'Point1D' as_point1d(point, ...)
as_point1d(...) ## S3 method for class 'numeric' as_point1d(a, b, ...) ## S3 method for class 'character' as_point1d(x, ...) ## S3 method for class 'Coord1D' as_point1d(normal, ...) ## S3 method for class 'Point1D' as_point1d(point, ...)
... |
Passed to other function such as |
a , b
|
Numeric vectors that parameterize the point via the equation |
x |
A (character) vector to be cast to a Point1D object |
normal |
Coord1D class object. |
point |
A Point1D object |
p1 <- as_point1d(a = 1, b = 0)
p1 <- as_point1d(a = 1, b = 0)
as_transform1d()
casts to a transform1d()
affine transformation matrix
as_transform1d(x, ...) ## S3 method for class 'transform1d' as_transform1d(x, ...) ## Default S3 method: as_transform1d(x, ...)
as_transform1d(x, ...) ## S3 method for class 'transform1d' as_transform1d(x, ...) ## Default S3 method: as_transform1d(x, ...)
x |
An object that can be cast to a |
... |
Further arguments passed to or from other methods |
A transform1d()
object
m <- diag(2L) as_transform1d(m)
m <- diag(2L) as_transform1d(m)
as_transform2d()
casts to a transform2d()
affine transformation matrix
as_transform2d(x, ...) ## S3 method for class 'transform2d' as_transform2d(x, ...) ## Default S3 method: as_transform2d(x, ...)
as_transform2d(x, ...) ## S3 method for class 'transform2d' as_transform2d(x, ...) ## Default S3 method: as_transform2d(x, ...)
x |
An object that can be cast to a |
... |
Further arguments passed to or from other methods |
A transform2d()
object
m <- diag(3L) as_transform2d(m)
m <- diag(3L) as_transform2d(m)
as_transform3d()
casts to a transform3d()
affine transformation matrix
as_transform3d(x, ...) ## S3 method for class 'transform3d' as_transform3d(x, ...) ## Default S3 method: as_transform3d(x, ...)
as_transform3d(x, ...) ## S3 method for class 'transform3d' as_transform3d(x, ...) ## Default S3 method: as_transform3d(x, ...)
x |
An object that can be cast to a |
... |
Further arguments passed to or from other methods |
A transform3d()
object
m <- diag(4L) as_transform3d(m)
m <- diag(4L) as_transform3d(m)
range()
computes axis-aligned ranges for
Coord1D, Coord2D, and Coord3D class objects.
## S3 method for class 'Coord1D' range(..., na.rm = FALSE) ## S3 method for class 'Coord2D' range(..., na.rm = FALSE) ## S3 method for class 'Coord3D' range(..., na.rm = FALSE)
## S3 method for class 'Coord1D' range(..., na.rm = FALSE) ## S3 method for class 'Coord2D' range(..., na.rm = FALSE) ## S3 method for class 'Coord3D' range(..., na.rm = FALSE)
... |
|
na.rm |
logical, indicating if |
Either a Coord1D, Coord2D, or Coord3D object of length two. The first element will have the minimum x/y(/z) coordinates and the second element will have the maximum x/y(/z) coordinates of the axis-aligned ranges.
range(as_coord2d(rnorm(5), rnorm(5))) range(as_coord3d(rnorm(5), rnorm(5), rnorm(5)))
range(as_coord2d(rnorm(5), rnorm(5))) range(as_coord3d(rnorm(5), rnorm(5), rnorm(5)))
mean()
computes centroids for Coord1D, Coord2D, and Coord3D class objects
## S3 method for class 'Coord1D' mean(x, ...) ## S3 method for class 'Coord2D' mean(x, ...) ## S3 method for class 'Coord3D' mean(x, ...)
## S3 method for class 'Coord1D' mean(x, ...) ## S3 method for class 'Coord2D' mean(x, ...) ## S3 method for class 'Coord3D' mean(x, ...)
x |
|
... |
Passed to |
A Coord1D, Coord2D, or Coord3D class object of length one
p <- as_coord2d(x = 1:4, y = 1:4) print(mean(p)) print(sum(p) / length(p)) # less efficient alternative p <- as_coord3d(x = 1:4, y = 1:4, z = 1:4) print(mean(p))
p <- as_coord2d(x = 1:4, y = 1:4) print(mean(p)) print(sum(p) / length(p)) # less efficient alternative p <- as_coord3d(x = 1:4, y = 1:4, z = 1:4) print(mean(p))
convex_hull2d()
is a S3 generic for computing the convex hull of an object.
There is an implemented method supporting Coord2D class objects
using grDevices::chull()
to compute the convex hull.
convex_hull2d(x, ...) ## S3 method for class 'Coord2D' convex_hull2d(x, ...)
convex_hull2d(x, ...) ## S3 method for class 'Coord2D' convex_hull2d(x, ...)
x |
An object representing object to compute convex hull of such as a Coord2D class object. |
... |
Further arguments passed to or from other methods. |
An object of same class as x
representing just the subset of points on the convex hull.
The method for Coord2D class objects returns these points in counter-clockwise order.
p <- as_coord2d(x = rnorm(25), y = rnorm(25)) print(convex_hull2d(p)) # Equivalent to following caculation using `grDevices::chull()` all.equal(convex_hull2d(p), p[rev(grDevices::chull(as.list(p)))])
p <- as_coord2d(x = rnorm(25), y = rnorm(25)) print(convex_hull2d(p)) # Equivalent to following caculation using `grDevices::chull()` all.equal(convex_hull2d(p), p[rev(grDevices::chull(as.list(p)))])
Coord1D
is an R6::R6Class()
object representing two-dimensional points
represented by Cartesian Coordinates.
xw
A two-column matrix representing the homogeneous coordinates. The first column is the "x" coordinates and the second column is all ones.
x
A numeric vector of x-coordinates.
new()
Coord1D$new(xw)
xw
A matrix with three columns representing (homogeneous) coordinates. The first column represents x coordinates and the last column is all ones. Column names should be "x" and "w".
print()
Coord1D$print(n = NULL, ...)
n
Number of coordinates to print. If NULL
print all of them.
...
Passed to format.default()
.
project()
Coord1D$project(point = as_point1d("origin"), ...)
point
A Point1D object of length one representing the point
you with to reflect across or project to or an object coercible to one by as_point1d(point, ...)
such as "origin".
...
Passed to project1d()
.
reflect()
Coord1D$reflect(point = as_point1d("origin"), ...)
point
A Point1D object of length one representing the point
you with to reflect across or project to or an object coercible to one by as_point1d(point, ...)
such as "origin".
...
Passed to reflect1d()
.
scale()
Coord1D$scale(x_scale = 1)
x_scale
Scaling factor to apply to x coordinates
translate()
Coord1D$translate(x = as_coord1d(0), ...)
transform()
Coord1D$transform(mat = transform1d())
mat
A 2x2 matrix representing a post-multiplied affine transformation matrix.
The last column must be equal to c(0, 1)
.
If the last row is c(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 1x1 matrix we'll quietly add a final column/row equal to c(0, 1)
.
clone()
The objects of this class are cloneable with this method.
Coord1D$clone(deep = FALSE)
deep
Whether to make a deep clone.
p <- as_coord1d(x = rnorm(100, 2)) print(p, n = 10L) pc <- mean(p) # Centroid # method chained affine transformation matrices are auto-pre-multiplied p$ translate(-pc)$ reflect("origin")$ print(n = 10L)
p <- as_coord1d(x = rnorm(100, 2)) print(p, n = 10L) pc <- mean(p) # Centroid # method chained affine transformation matrices are auto-pre-multiplied p$ translate(-pc)$ reflect("origin")$ print(n = 10L)
Coord2D
is an R6::R6Class()
object representing two-dimensional points
represented by Cartesian Coordinates.
xyw
A three-column matrix representing the homogeneous coordinates. The first two columns are "x" and "y" coordinates and the third column is all ones.
x
A numeric vector of x-coordinates.
y
A numeric vector of y-coordinates.
new()
Coord2D$new(xyw)
xyw
A matrix with three columns representing (homogeneous) coordinates. The first two columns represent x and y coordinates and the last column is all ones. Column names should be "x", "y", and "w".
permute()
Coord2D$permute(permutation = c("xy", "yx"))
permutation
Either "xy" (no permutation) or "yx" (permute x and y axes)
print()
Coord2D$print(n = NULL, ...)
n
Number of coordinates to print. If NULL
print all of them.
...
Passed to format.default()
.
project()
Coord2D$project(line = as_line2d("x-axis"), ..., scale = 0)
line
A Line2D object of length one representing the line
you with to reflect across or project to or an object coercible to one by as_line2d(line, ...)
such as "x-axis" or "y-axis".
...
Passed to project2d()
scale
Oblique projection scale factor.
A degenerate 0
value indicates an orthogonal projection.
reflect()
Coord2D$reflect(line = as_line2d("x-axis"), ...)
line
A Line2D object of length one representing the line
you with to reflect across or project to or an object coercible to one by as_line2d(line, ...)
such as "x-axis" or "y-axis".
...
Passed to reflect2d()
.
rotate()
Coord2D$rotate(theta = angle(0), ...)
theta
An angle()
object of length one or an object coercible to one by as_angle(theta, ...)
.
...
Passed to as_angle()
.
scale()
Coord2D$scale(x_scale = 1, y_scale = x_scale)
x_scale
Scaling factor to apply to x coordinates
y_scale
Scaling factor to apply to y coordinates
shear()
Coord2D$shear(xy_shear = 0, yx_shear = 0)
xy_shear
Horizontal shear factor: x = x + xy_shear * y
yx_shear
Vertical shear factor: y = yx_shear * x + y
translate()
Coord2D$translate(x = as_coord2d(0, 0), ...)
transform()
Coord2D$transform(mat = transform2d())
mat
A 3x3 matrix representing a post-multiplied affine transformation matrix.
The last column must be equal to c(0, 0, 1)
.
If the last row is c(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 2x2 matrix (such as a 2x2 post-multiplied 2D rotation matrix)
we'll quietly add a final column/row equal to c(0, 0, 1)
.
clone()
The objects of this class are cloneable with this method.
Coord2D$clone(deep = FALSE)
deep
Whether to make a deep clone.
p <- as_coord2d(x = rnorm(100, 2), y = rnorm(100, 2)) print(p, n = 10) pc <- mean(p) # Centroid # method chained affine transformation matrices are auto-pre-multiplied p$ translate(-pc)$ shear(x = 1, y = 0)$ reflect("x-axis")$ rotate(90, "degrees")$ print(n = 10)
p <- as_coord2d(x = rnorm(100, 2), y = rnorm(100, 2)) print(p, n = 10) pc <- mean(p) # Centroid # method chained affine transformation matrices are auto-pre-multiplied p$ translate(-pc)$ shear(x = 1, y = 0)$ reflect("x-axis")$ rotate(90, "degrees")$ print(n = 10)
Coord3D
is an R6::R6Class()
object representing three-dimensional points
represented by Cartesian Coordinates.
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.
new()
Coord3D$new(xyzw)
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".
permute()
Coord3D$permute(permutation = c("xyz", "xzy", "yxz", "yzx", "zyx", "zxy"))
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)
print()
Coord3D$print(n = NULL, ...)
n
Number of coordinates to print. If NULL
print all of them.
...
Passed to format.default()
.
project()
Coord3D$project( plane = as_plane3d("xy-plane"), ..., scale = 0, alpha = angle(45, "degrees") )
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.
reflect()
Coord3D$reflect(plane = as_plane3d("xy-plane"), ...)
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()
.
rotate()
Coord3D$rotate(axis = as_coord3d("z-axis"), theta = angle(0), ...)
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()
.
scale()
Coord3D$scale(x_scale = 1, y_scale = x_scale, z_scale = x_scale)
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
shear()
Coord3D$shear( xy_shear = 0, xz_shear = 0, yx_shear = 0, yz_shear = 0, zx_shear = 0, zy_shear = 0 )
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
translate()
Coord3D$translate(x = as_coord3d(0, 0, 0), ...)
transform()
Coord3D$transform(mat = transform3d())
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)
.
clone()
The objects of this class are cloneable with this method.
Coord3D$clone(deep = FALSE)
deep
Whether to make a deep clone.
p <- as_coord3d(x = rnorm(100, 2), y = rnorm(100, 2), z = rnorm(100, 2)) print(p, n = 10) 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)
p <- as_coord3d(x = rnorm(100, 2), y = rnorm(100, 2), z = rnorm(100, 2)) print(p, n = 10) 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)
cross_product3d()
computes the cross product of two Coord3D class vectors.
cross_product3d(x, y)
cross_product3d(x, y)
x |
A Coord3D class vector. |
y |
A Coord3D class vector. |
A Coord3D class vector
x <- as_coord3d(2, 3, 4) y <- as_coord3d(5, 6, 7) cross_product3d(x, y)
x <- as_coord3d(2, 3, 4) y <- as_coord3d(5, 6, 7) cross_product3d(x, y)
distance1d()
computes 1D Euclidean distances.
distance1d(x, y)
distance1d(x, y)
x |
|
y |
p <- as_coord1d(x = 1:4) distance1d(p, as_coord1d(0))
p <- as_coord1d(x = 1:4) distance1d(p, as_coord1d(0))
distance2d()
computes 2D Euclidean distances.
distance2d(x, y)
distance2d(x, y)
x |
|
y |
p <- as_coord2d(x = 1:4, y = 1:4) distance2d(p, as_coord2d(0, 0))
p <- as_coord2d(x = 1:4, y = 1:4) distance2d(p, as_coord2d(0, 0))
distance3d()
computes 3D Euclidean distances.
distance3d(x, y)
distance3d(x, y)
x |
|
y |
p <- as_coord3d(x = 1:4, y = 1:4, z = 1:4) distance3d(p, as_coord3d("origin"))
p <- as_coord3d(x = 1:4, y = 1:4, z = 1:4) distance3d(p, as_coord3d("origin"))
plot()
plots Coord1D and Coord2D class objects while
points()
draws Coord1D and Coord2D class objects
and lines()
draws Point1D and Line2D class objects to an existing plot.
If the suggested ggplot2 and rgl packages are available we also register ggplot2::autolayer()
methods for Coord1D, Coord2D, Point1D, and Line2D class objects and a rgl::plot3d()
method for Coord3D class objects.
## S3 method for class 'Coord1D' plot(x, ...) ## S3 method for class 'Coord1D' points(x, ...) ## S3 method for class 'Point1D' lines(x, ...) ## S3 method for class 'Coord2D' plot(x, ...) ## S3 method for class 'Coord2D' points(x, ...) ## S3 method for class 'Line2D' lines(x, ...)
## S3 method for class 'Coord1D' plot(x, ...) ## S3 method for class 'Coord1D' points(x, ...) ## S3 method for class 'Point1D' lines(x, ...) ## S3 method for class 'Coord2D' plot(x, ...) ## S3 method for class 'Coord2D' points(x, ...) ## S3 method for class 'Line2D' lines(x, ...)
x |
A supported object to plot. |
... |
Passed to the underlying plot method. |
Used for its side effect of drawing to the graphics device.
c1 <- as_coord2d(x = 0, y = 1:10) l <- as_line2d(a = 1, b = -1, c = 0) # y = x c2 <- c1$clone()$reflect(l) plot(c1, xlim = c(-1, 11), ylim = c(-1, 11), main = "2D reflection across a line") lines(l) points(c2, col = "red") c1 <- as_coord2d(x = 1:10, y = 1:10) l <- as_line2d(a = -1, b = 0, c = 0) # x = 0 c2 <- c1$clone()$project(l) if (require("ggplot2", quietly = TRUE, include.only = c("ggplot", "autolayer", "labs"))) { ggplot() + autolayer(c1) + autolayer(l) + autolayer(c2, color = "red") + labs(title = "2D projection onto a line") } c1 <- as_coord1d(x = seq.int(-4, -1)) pt <- as_point1d(a = 1, b = 0) # x = 0 c2 <- c1$clone()$reflect(pt) plot(c1, xlim = c(-5, 5), main = "1D reflection across a point") lines(pt) points(c2, col = "red") # 3D reflection across a plane c1 <- as_coord3d(x = 1:10, y = 1:10, z = 1:10) pl <- as_plane3d(a = 0, b = 0, c = -1, d = 2) # z = 2 c2 <- c1$clone()$reflect(pl) if (require("rgl", quietly = TRUE, include.only = c("plot3d", "planes3d", "points3d"))) { plot3d(c1, size = 8) planes3d(as.data.frame(pl), d = pl$d, color = "grey", alpha = 0.6) points3d(as.data.frame(c2), col = "red", size = 8) }
c1 <- as_coord2d(x = 0, y = 1:10) l <- as_line2d(a = 1, b = -1, c = 0) # y = x c2 <- c1$clone()$reflect(l) plot(c1, xlim = c(-1, 11), ylim = c(-1, 11), main = "2D reflection across a line") lines(l) points(c2, col = "red") c1 <- as_coord2d(x = 1:10, y = 1:10) l <- as_line2d(a = -1, b = 0, c = 0) # x = 0 c2 <- c1$clone()$project(l) if (require("ggplot2", quietly = TRUE, include.only = c("ggplot", "autolayer", "labs"))) { ggplot() + autolayer(c1) + autolayer(l) + autolayer(c2, color = "red") + labs(title = "2D projection onto a line") } c1 <- as_coord1d(x = seq.int(-4, -1)) pt <- as_point1d(a = 1, b = 0) # x = 0 c2 <- c1$clone()$reflect(pt) plot(c1, xlim = c(-5, 5), main = "1D reflection across a point") lines(pt) points(c2, col = "red") # 3D reflection across a plane c1 <- as_coord3d(x = 1:10, y = 1:10, z = 1:10) pl <- as_plane3d(a = 0, b = 0, c = -1, d = 2) # z = 2 c2 <- c1$clone()$reflect(pl) if (require("rgl", quietly = TRUE, include.only = c("plot3d", "planes3d", "points3d"))) { plot3d(c1, size = 8) planes3d(as.data.frame(pl), d = pl$d, color = "grey", alpha = 0.6) points3d(as.data.frame(c2), col = "red", size = 8) }
arcsine()
, arccosine()
, arctangent()
,
arcsecant()
, arccosecant()
, and arccotangent()
are
inverse trigonometric functions that return angle()
vectors
with a user chosen angular unit.
arcsine( x, unit = getOption("affiner_angular_unit", "degrees"), tolerance = sqrt(.Machine$double.eps) ) arccosine( x, unit = getOption("affiner_angular_unit", "degrees"), tolerance = sqrt(.Machine$double.eps) ) arctangent(x, unit = getOption("affiner_angular_unit", "degrees"), y = NULL) arcsecant(x, unit = getOption("affiner_angular_unit", "degrees")) arccosecant(x, unit = getOption("affiner_angular_unit", "degrees")) arccotangent(x, unit = getOption("affiner_angular_unit", "degrees"))
arcsine( x, unit = getOption("affiner_angular_unit", "degrees"), tolerance = sqrt(.Machine$double.eps) ) arccosine( x, unit = getOption("affiner_angular_unit", "degrees"), tolerance = sqrt(.Machine$double.eps) ) arctangent(x, unit = getOption("affiner_angular_unit", "degrees"), y = NULL) arcsecant(x, unit = getOption("affiner_angular_unit", "degrees")) arccosecant(x, unit = getOption("affiner_angular_unit", "degrees")) arccotangent(x, unit = getOption("affiner_angular_unit", "degrees"))
x |
A numeric vector |
unit |
A string of the desired angular unit. Supports the following strings
(note we ignore any punctuation and space characters as well as any trailing
|
tolerance |
If |
y |
A numeric vector or |
An angle()
vector
arccosine(-1, "degrees") arcsine(0, "turns") arctangent(0, "gradians") arccosecant(-1, "degrees") arcsecant(1, "degrees") arccotangent(1, "half-turns") # `base::atan2(y, x)` computes the angle of the vector from origin to (x, y) as_angle(as_coord2d(x = 1, y = 1), "degrees")
arccosine(-1, "degrees") arcsine(0, "turns") arctangent(0, "gradians") arccosecant(-1, "degrees") arcsecant(1, "degrees") arccotangent(1, "half-turns") # `base::atan2(y, x)` computes the angle of the vector from origin to (x, y) as_angle(as_coord2d(x = 1, y = 1), "degrees")
is_angle()
tests whether an object is an angle vector
is_angle(x)
is_angle(x)
x |
An object |
A logical value
a <- angle(180, "degrees") is_angle(a) is_angle(pi)
a <- angle(180, "degrees") is_angle(a) is_angle(pi)
is_congruent()
is a S3 generic that tests whether two different objects are “congruent”.
The is_congruent()
method for angle()
classes tests whether two angles are congruent.
is_congruent(x, y, ...) ## S3 method for class 'numeric' is_congruent(x, y, ..., tolerance = sqrt(.Machine$double.eps)) ## S3 method for class 'angle' is_congruent( x, y, ..., mod_turns = TRUE, tolerance = sqrt(.Machine$double.eps) )
is_congruent(x, y, ...) ## S3 method for class 'numeric' is_congruent(x, y, ..., tolerance = sqrt(.Machine$double.eps)) ## S3 method for class 'angle' is_congruent( x, y, ..., mod_turns = TRUE, tolerance = sqrt(.Machine$double.eps) )
x , y
|
Two objects to test whether they are “"congruent"”. |
... |
Further arguments passed to or from other methods. |
tolerance |
Angles (coerced to half-turns) or numerics with differences smaller
than |
mod_turns |
If |
A logical vector
# Use `is_congruent()` to check if two angles are "congruent" a1 <- angle(180, "degrees") a2 <- angle(pi, "radians") a3 <- angle(-180, "degrees") # Only congruent modulus full turns a1 == a2 isTRUE(all.equal(a1, a2)) is_congruent(a1, a2) is_congruent(a1, a2, mod_turns = FALSE) a1 == a3 isTRUE(all.equal(a1, a3)) is_congruent(a1, a3) is_congruent(a1, a3, mod_turns = FALSE)
# Use `is_congruent()` to check if two angles are "congruent" a1 <- angle(180, "degrees") a2 <- angle(pi, "radians") a3 <- angle(-180, "degrees") # Only congruent modulus full turns a1 == a2 isTRUE(all.equal(a1, a2)) is_congruent(a1, a2) is_congruent(a1, a2, mod_turns = FALSE) a1 == a3 isTRUE(all.equal(a1, a3)) is_congruent(a1, a3) is_congruent(a1, a3, mod_turns = FALSE)
is_coord1d()
tests whether an object has a "Coord1D" class
is_coord1d(x)
is_coord1d(x)
x |
An object |
A logical value
p <- as_coord1d(x = sample.int(10, 3)) is_coord1d(p)
p <- as_coord1d(x = sample.int(10, 3)) is_coord1d(p)
is_coord2d()
tests whether an object has a "Coord2D" class
is_coord2d(x)
is_coord2d(x)
x |
An object |
A logical value
p <- as_coord2d(x = sample.int(10, 3), y = sample.int(10, 3)) is_coord2d(p)
p <- as_coord2d(x = sample.int(10, 3), y = sample.int(10, 3)) is_coord2d(p)
is_coord3d()
tests whether an object has a "Coord3D" class
is_coord3d(x)
is_coord3d(x)
x |
An object |
A logical value
p <- as_coord3d(x = sample.int(10, 3), y = sample.int(10, 3), z = sample.int(10, 3)) is_coord3d(p)
p <- as_coord3d(x = sample.int(10, 3), y = sample.int(10, 3), z = sample.int(10, 3)) is_coord3d(p)
is_line2d()
tests whether an object has a "Line2D" class
is_line2d(x)
is_line2d(x)
x |
An object |
A logical value
l <- as_line2d(a = 1, b = 2, c = 3) is_line2d(l)
l <- as_line2d(a = 1, b = 2, c = 3) is_line2d(l)
is_plane3d()
tests whether an object has a "Plane3D" class
is_plane3d(x)
is_plane3d(x)
x |
An object |
A logical value
p <- as_plane3d(a = 1, b = 2, c = 3, 4) is_plane3d(p)
p <- as_plane3d(a = 1, b = 2, c = 3, 4) is_plane3d(p)
is_point1d()
tests whether an object has a "Point1D" class
is_point1d(x)
is_point1d(x)
x |
An object |
A logical value
p <- as_point1d(a = 1, b = 5) is_point1d(p)
p <- as_point1d(a = 1, b = 5) is_point1d(p)
is_transform1d()
tests if object is a transform1d()
affine transformation matrix
is_transform1d(x)
is_transform1d(x)
x |
An object |
A logical value
m <- transform1d(diag(2L)) is_transform1d(m) is_transform1d(diag(2L))
m <- transform1d(diag(2L)) is_transform1d(m) is_transform1d(diag(2L))
is_transform2d()
tests if object is a transform2d()
affine transformation matrix
is_transform2d(x)
is_transform2d(x)
x |
An object |
A logical value
m <- transform2d(diag(3L)) is_transform2d(m) is_transform2d(diag(3L))
m <- transform2d(diag(3L)) is_transform2d(m) is_transform2d(diag(3L))
is_transform3d()
tests if object is a transform3d()
affine transformation matrix
is_transform3d(x)
is_transform3d(x)
x |
An object |
A logical value
m <- transform3d(diag(4L)) is_transform3d(m) is_transform3d(diag(4L))
m <- transform3d(diag(4L)) is_transform3d(m) is_transform3d(diag(4L))
isometricCube()
is a grid grob function to render
isometric cube faces by automatically wrapping around affineGrob()
.
isocubeGrob( top, right, left, gp_border = grid::gpar(fill = NA, col = "black", lwd = 12), name = NULL, gp = grid::gpar(), vp = NULL ) grid.isocube(...)
isocubeGrob( top, right, left, gp_border = grid::gpar(fill = NA, col = "black", lwd = 12), name = NULL, gp = grid::gpar(), vp = NULL ) grid.isocube(...)
top |
A grid grob object to use as the top side of the cube. ggplot2 objects will be coerced by |
right |
A grid grob object to use as the right side of the cube. ggplot2 objects will be coerced by |
left |
A grid grob object to use as the left side of the cube. ggplot2 objects will be coerced by |
gp_border |
A |
name |
A character identifier (for grid). |
gp |
A |
vp |
A |
... |
Passed to |
Any ggplot2
objects are coerced to grobs by ggplot2::ggplotGrob()
. Depending on what you'd like
to do you may want to instead manually convert a ggplot2 object gg
to a grob with gtable::gtable_filter(ggplot2::ggplotGrob(gg), "panel")
.
A grid::gTree()
(grob) object of class "isocube".
As a side effect grid.isocube()
draws to the active graphics device.
if (require("grid") && getRversion() >= "4.2.0" && isTRUE(dev.capabilities()$transformations)) { # Only works if active graphics device supports affine transformations # such as `png(type="cairo")` on R 4.2+ grid.newpage() gp_text <- gpar(fontsize = 72) grid.isocube(top = textGrob("top", gp = gp_text), right = textGrob("right", gp = gp_text), left = textGrob("left", gp = gp_text)) } if (require("grid") && getRversion() >= "4.2.0" && isTRUE(dev.capabilities()$transformations)) { colors <- c("#D55E00", "#009E73", "#56B4E9") spacings <- c(0.25, 0.2, 0.25) texts <- c("pkgname", "left\nface", "right\nface") rots <- c(45, 0, 0) fontsizes <- c(52, 80, 80) sides <- c("top", "left", "right") types <- gridpattern::names_polygon_tiling[c(5, 7, 9)] l_grobs <- list() grid.newpage() for (i in 1:3) { if (requireNamespace("gridpattern", quietly = TRUE)) { bg <- gridpattern::grid.pattern_polygon_tiling( colour = "grey80", fill = c(colors[i], "white"), type = types[i], spacing = spacings[i], draw = FALSE) } else { bg <- rectGrob(gp = gpar(col = NA, fill = colors[i])) } text <- textGrob(texts[i], rot = rots[i], gp = gpar(fontsize = fontsizes[i])) l_grobs[[sides[i]]] <- grobTree(bg, text) } grid.newpage() grid.isocube(top = l_grobs$top, right = l_grobs$right, left = l_grobs$left) }
if (require("grid") && getRversion() >= "4.2.0" && isTRUE(dev.capabilities()$transformations)) { # Only works if active graphics device supports affine transformations # such as `png(type="cairo")` on R 4.2+ grid.newpage() gp_text <- gpar(fontsize = 72) grid.isocube(top = textGrob("top", gp = gp_text), right = textGrob("right", gp = gp_text), left = textGrob("left", gp = gp_text)) } if (require("grid") && getRversion() >= "4.2.0" && isTRUE(dev.capabilities()$transformations)) { colors <- c("#D55E00", "#009E73", "#56B4E9") spacings <- c(0.25, 0.2, 0.25) texts <- c("pkgname", "left\nface", "right\nface") rots <- c(45, 0, 0) fontsizes <- c(52, 80, 80) sides <- c("top", "left", "right") types <- gridpattern::names_polygon_tiling[c(5, 7, 9)] l_grobs <- list() grid.newpage() for (i in 1:3) { if (requireNamespace("gridpattern", quietly = TRUE)) { bg <- gridpattern::grid.pattern_polygon_tiling( colour = "grey80", fill = c(colors[i], "white"), type = types[i], spacing = spacings[i], draw = FALSE) } else { bg <- rectGrob(gp = gpar(col = NA, fill = colors[i])) } text <- textGrob(texts[i], rot = rots[i], gp = gpar(fontsize = fontsizes[i])) l_grobs[[sides[i]]] <- grobTree(bg, text) } grid.newpage() grid.isocube(top = l_grobs$top, right = l_grobs$right, left = l_grobs$left) }
Line2D
is an R6::R6Class()
object representing two-dimensional lines.
a
Numeric vector that parameterizes the line via the equation a * x + b * y + c = 0
.
b
Numeric vector that parameterizes the line via the equation a * x + b * y + c = 0
.
c
Numeric vector that parameterizes the line via the equation a * x + b * y + c = 0
.
new()
Line2D$new(a, b, c)
a
Numeric vector that parameterizes the line via the equation a * x + b * y + c = 0
.
b
Numeric vector that parameterizes the line via the equation a * x + b * y + c = 0
.
c
Numeric vector that parameterizes the line via the equation a * x + b * y + c = 0
.
print()
Line2D$print(n = NULL, ...)
n
Number of lines to print. If NULL
print all of them.
...
Passed to format.default()
.
clone()
The objects of this class are cloneable with this method.
Line2D$clone(deep = FALSE)
deep
Whether to make a deep clone.
p1 <- as_coord2d(x = 5, y = 10) p2 <- as_coord2d(x = 7, y = 12) theta <- degrees(45) as_line2d(theta, p1) as_line2d(p1, p2)
p1 <- as_coord2d(x = 5, y = 10) p2 <- as_coord2d(x = 7, y = 12) theta <- degrees(45) as_line2d(theta, p1) as_line2d(p1, p2)
normal2d()
is an S3 generic that computes a 2D normal vector.
normal2d(x, ...) ## S3 method for class 'Coord2D' normal2d(x, ..., normalize = TRUE) ## S3 method for class 'Line2D' normal2d(x, ..., normalize = TRUE)
normal2d(x, ...) ## S3 method for class 'Coord2D' normal2d(x, ..., normalize = TRUE) ## S3 method for class 'Line2D' normal2d(x, ..., normalize = TRUE)
x |
Object to compute a 2D normal vector for such as a Line2D object. |
... |
Passed to or from other methods. |
normalize |
If |
A Coord2D (normal) vector
p <- as_coord2d(x = 2, y = 3) normal2d(p) normal2d(p, normalize = FALSE)
p <- as_coord2d(x = 2, y = 3) normal2d(p) normal2d(p, normalize = FALSE)
normal3d()
is an S3 generic that computes a 3D normal vector.
normal3d(x, ...) ## S3 method for class 'Coord3D' normal3d(x, cross, ..., normalize = TRUE) ## S3 method for class 'character' normal3d(x, ..., normalize = TRUE) ## S3 method for class 'Plane3D' normal3d(x, ..., normalize = TRUE)
normal3d(x, ...) ## S3 method for class 'Coord3D' normal3d(x, cross, ..., normalize = TRUE) ## S3 method for class 'character' normal3d(x, ..., normalize = TRUE) ## S3 method for class 'Plane3D' normal3d(x, ..., normalize = TRUE)
x |
Object to compute a 3D normal vector for such as a Plane3D object |
... |
Passed to other methods such as |
cross |
A Coord3D vector.
We'll compute the normal of |
normalize |
If |
A Coord3D (normal) vector
normal3d("xy-plane") normal3d(as_coord3d(2, 0, 0), cross = as_coord3d(0, 2, 0))
normal3d("xy-plane") normal3d(as_coord3d(2, 0, 0), cross = as_coord3d(0, 2, 0))
Plane3D
is an R6::R6Class()
object representing three-dimensional planes.
a
Numeric vector that parameterizes the plane via the equation a * x + b * y + c * z + d = 0
.
b
Numeric vector that parameterizes the plane via the equation a * x + b * y + c * z + d = 0
.
c
Numeric vector that parameterizes the plane via the equation a * x + b * y + c * z + d = 0
.
d
Numeric vector that parameterizes the plane via the equation a * x + b * y + c * z + d = 0
.
new()
Plane3D$new(a, b, c, d)
a
Numeric vector that parameterizes the plane via the equation a * x + b * y + c * z + d = 0
.
b
Numeric vector that parameterizes the plane via the equation a * x + b * y + c * z + d = 0
.
c
Numeric vector that parameterizes the plane via the equation a * x + b * y + c * z + d = 0
.
d
Numeric vector that parameterizes the plane via the equation a * x + b * y + c * z + d = 0
.
print()
Plane3D$print(n = NULL, ...)
n
Number of lines to print. If NULL
print all of them.
...
Passed to format.default()
.
clone()
The objects of this class are cloneable with this method.
Plane3D$clone(deep = FALSE)
deep
Whether to make a deep clone.
Point1D
is an R6::R6Class()
object representing one-dimensional points.
a
Numeric vector that parameterizes the point via the equation a * x + b = 0
.
b
Numeric vector that parameterizes the point via the equation a * x + b = 0
.
new()
Point1D$new(a, b)
a
Numeric vector that parameterizes the line via the equation a * x + b = 0
.
b
Numeric vector that parameterizes the line via the equation a * x + b = 0
.
print()
Point1D$print(n = NULL, ...)
n
Number of lines to print. If NULL
print all of them.
...
Passed to format.default()
.
clone()
The objects of this class are cloneable with this method.
Point1D$clone(deep = FALSE)
deep
Whether to make a deep clone.
p1 <- as_point1d(a = 1, b = 5)
p1 <- as_point1d(a = 1, b = 5)
rotate3d_to_AA()
converts from (post-multiplied) rotation matrix
to an axis-angle representation of 3D rotations.
rotate3d_to_AA( mat = diag(4), unit = getOption("affiner_angular_unit", "degrees") )
rotate3d_to_AA( mat = diag(4), unit = getOption("affiner_angular_unit", "degrees") )
mat |
3D rotation matrix (post-multiplied).
If you have a pre-multiplied rotation matrix
simply transpose it with |
unit |
A string of the desired angular unit. Supports the following strings
(note we ignore any punctuation and space characters as well as any trailing
|
https://en.wikipedia.org/wiki/Axis-angle_representation for more details
about the Axis-angle representation of 3D rotations.
rotate3d()
can be used to convert from an axis-angle representation to a rotation matrix.
# axis-angle representation of 90 degree rotation about the x-axis rotate3d_to_AA(rotate3d("x-axis", 90, unit = "degrees")) # find Axis-Angle representation of first rotating about x-axis 180 degrees # and then rotating about z-axis 45 degrees R <- rotate3d("x-axis", 180, unit = "degrees") %*% rotate3d("z-axis", 45, unit = "degrees") AA <- rotate3d_to_AA(R) # Can use `rotate3d()` to convert back to rotation matrix representation all.equal(R, do.call(rotate3d, AA))
# axis-angle representation of 90 degree rotation about the x-axis rotate3d_to_AA(rotate3d("x-axis", 90, unit = "degrees")) # find Axis-Angle representation of first rotating about x-axis 180 degrees # and then rotating about z-axis 45 degrees R <- rotate3d("x-axis", 180, unit = "degrees") %*% rotate3d("z-axis", 45, unit = "degrees") AA <- rotate3d_to_AA(R) # Can use `rotate3d()` to convert back to rotation matrix representation all.equal(R, do.call(rotate3d, AA))
transform1d()
, reflect1d()
, scale2d()
,
and translate1d()
create 1D affine transformation matrix objects.
transform1d(mat = diag(2L)) project1d(point = as_point1d("origin"), ...) reflect1d(point = as_point1d("origin"), ...) scale1d(x_scale = 1) translate1d(x = as_coord1d(0), ...)
transform1d(mat = diag(2L)) project1d(point = as_point1d("origin"), ...) reflect1d(point = as_point1d("origin"), ...) scale1d(x_scale = 1) translate1d(x = as_coord1d(0), ...)
mat |
A 2x2 matrix representing a post-multiplied affine transformation matrix.
The last column must be equal to |
point |
A Point1D object of length one representing the point
you with to reflect across or project to or an object coercible to one by |
... |
Passed to |
x_scale |
Scaling factor to apply to x coordinates |
x |
A Coord1D object of length one or an object coercible to one by |
transform1d()
User supplied (post-multiplied) affine transformation matrix
.
reflect1d()
Reflections across a point.
scale1d()
Scale the x-coordinates by multiplicative scale factors.
translate1d()
Translate the coordinates by a Coord1D class object parameter.
transform1d()
1D affine transformation matrix objects are meant to be
post-multiplied and therefore should not be multiplied in reverse order.
Note the Coord1D class object methods auto-pre-multiply affine transformations
when "method chaining" so pre-multiplying affine transformation matrices
to do a single cumulative transformation instead of a method chain of multiple transformations
will not improve performance as much as as it does in other R packages.
To convert a pre-multiplied 1D affine transformation matrix to a post-multiplied one
simply compute its transpose using t()
. To get an inverse transformation matrix
from an existing transformation matrix that does the opposite transformations
simply compute its inverse using solve()
.
A 2x2 post-multiplied affine transformation matrix with classes "transform1d" and "at_matrix"
p <- as_coord1d(x = sample(1:10, 3)) # {affiner} affine transformation matrices are post-multiplied # and therefore should **not** go in reverse order mat <- transform1d(diag(2)) %*% scale1d(2) %*% translate1d(x = -1) p1 <- p$ clone()$ transform(mat) # The equivalent result appyling affine transformations via method chaining p2 <- p$ clone()$ transform(diag(2))$ scale(2)$ translate(x = -1) all.equal(p1, p2)
p <- as_coord1d(x = sample(1:10, 3)) # {affiner} affine transformation matrices are post-multiplied # and therefore should **not** go in reverse order mat <- transform1d(diag(2)) %*% scale1d(2) %*% translate1d(x = -1) p1 <- p$ clone()$ transform(mat) # The equivalent result appyling affine transformations via method chaining p2 <- p$ clone()$ transform(diag(2))$ scale(2)$ translate(x = -1) all.equal(p1, p2)
transform2d()
, project2d()
, reflect2d()
, rotate2d()
, scale2d()
, shear2d()
,
and translate2d()
create 2D affine transformation matrix objects.
transform2d(mat = diag(3L)) permute2d(permutation = c("xy", "yx")) project2d(line = as_line2d("x-axis"), ..., scale = 0) reflect2d(line = as_line2d("x-axis"), ...) rotate2d(theta = angle(0), ...) scale2d(x_scale = 1, y_scale = x_scale) shear2d(xy_shear = 0, yx_shear = 0) translate2d(x = as_coord2d(0, 0), ...)
transform2d(mat = diag(3L)) permute2d(permutation = c("xy", "yx")) project2d(line = as_line2d("x-axis"), ..., scale = 0) reflect2d(line = as_line2d("x-axis"), ...) rotate2d(theta = angle(0), ...) scale2d(x_scale = 1, y_scale = x_scale) shear2d(xy_shear = 0, yx_shear = 0) translate2d(x = as_coord2d(0, 0), ...)
mat |
A 3x3 matrix representing a post-multiplied affine transformation matrix.
The last column must be equal to |
permutation |
Either "xy" (no permutation) or "yx" (permute x and y axes) |
line |
A Line2D object of length one representing the line
you with to reflect across or project to or an object coercible to one by |
... |
Passed to |
scale |
Oblique projection scale factor.
A degenerate |
theta |
An |
x_scale |
Scaling factor to apply to x coordinates |
y_scale |
Scaling factor to apply to y coordinates |
xy_shear |
Horizontal shear factor: |
yx_shear |
Vertical shear factor: |
x |
A Coord2D object of length one or an object coercible to one by |
transform2d()
User supplied (post-multiplied) affine transformation matrix
.
project2d()
Oblique vector projections onto a line parameterized by an oblique projection scale factor. A (degenerate) scale factor of zero results in an orthogonal projection.
reflect2d()
Reflections across a line.
To "flip" across both the x-axis and the y-axis use scale2d(-1)
.
rotate2d()
Rotations around the origin parameterized by an angle()
.
scale2d()
Scale the x-coordinates and/or the y-coordinates by multiplicative scale factors.
shear2d()
Shear the x-coordinates and/or the y-coordinates using shear factors.
translate2d()
Translate the coordinates by a Coord2D class object parameter.
transform2d()
2D affine transformation matrix objects are meant to be
post-multiplied and therefore should not be multiplied in reverse order.
Note the Coord2D class object methods auto-pre-multiply affine transformations
when "method chaining" so pre-multiplying affine transformation matrices
to do a single cumulative transformation instead of a method chain of multiple transformations
will not improve performance as much as as it does in other R packages.
To convert a pre-multiplied 2D affine transformation matrix to a post-multiplied one
simply compute its transpose using t()
. To get an inverse transformation matrix
from an existing transformation matrix that does the opposite transformations
simply compute its inverse using solve()
.
A 3x3 post-multiplied affine transformation matrix with classes "transform2d" and "at_matrix"
p <- as_coord2d(x = sample(1:10, 3), y = sample(1:10, 3)) # {affiner} affine transformation matrices are post-multiplied # and therefore should **not** go in reverse order mat <- transform2d(diag(3)) %*% reflect2d(as_coord2d(-1, 1)) %*% rotate2d(90, "degrees") %*% scale2d(1, 2) %*% shear2d(0.5, 0.5) %*% translate2d(x = -1, y = -1) p1 <- p$ clone()$ transform(mat) # The equivalent result appyling affine transformations via method chaining p2 <- p$ clone()$ transform(diag(3L))$ reflect(as_coord2d(-1, 1))$ rotate(90, "degrees")$ scale(1, 2)$ shear(0.5, 0.5)$ translate(x = -1, y = -1) all.equal(p1, p2)
p <- as_coord2d(x = sample(1:10, 3), y = sample(1:10, 3)) # {affiner} affine transformation matrices are post-multiplied # and therefore should **not** go in reverse order mat <- transform2d(diag(3)) %*% reflect2d(as_coord2d(-1, 1)) %*% rotate2d(90, "degrees") %*% scale2d(1, 2) %*% shear2d(0.5, 0.5) %*% translate2d(x = -1, y = -1) p1 <- p$ clone()$ transform(mat) # The equivalent result appyling affine transformations via method chaining p2 <- p$ clone()$ transform(diag(3L))$ reflect(as_coord2d(-1, 1))$ rotate(90, "degrees")$ scale(1, 2)$ shear(0.5, 0.5)$ translate(x = -1, y = -1) all.equal(p1, p2)
transform3d()
, project3d()
, reflect3d()
, rotate3d()
, scale3d()
, shear3d()
,
and translate3d()
create 3D affine transformation matrix objects.
transform3d(mat = diag(4L)) permute3d(permutation = c("xyz", "xzy", "yxz", "yzx", "zyx", "zxy")) project3d( plane = as_plane3d("xy-plane"), ..., scale = 0, alpha = angle(45, "degrees") ) reflect3d(plane = as_plane3d("xy-plane"), ...) rotate3d(axis = as_coord3d("z-axis"), theta = angle(0), ...) scale3d(x_scale = 1, y_scale = x_scale, z_scale = x_scale) shear3d( xy_shear = 0, xz_shear = 0, yx_shear = 0, yz_shear = 0, zx_shear = 0, zy_shear = 0 ) translate3d(x = as_coord3d(0, 0, 0), ...)
transform3d(mat = diag(4L)) permute3d(permutation = c("xyz", "xzy", "yxz", "yzx", "zyx", "zxy")) project3d( plane = as_plane3d("xy-plane"), ..., scale = 0, alpha = angle(45, "degrees") ) reflect3d(plane = as_plane3d("xy-plane"), ...) rotate3d(axis = as_coord3d("z-axis"), theta = angle(0), ...) scale3d(x_scale = 1, y_scale = x_scale, z_scale = x_scale) shear3d( xy_shear = 0, xz_shear = 0, yx_shear = 0, yz_shear = 0, zx_shear = 0, zy_shear = 0 ) translate3d(x = as_coord3d(0, 0, 0), ...)
mat |
A 4x4 matrix representing a post-multiplied affine transformation matrix.
The last column must be equal to |
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) |
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 |
... |
Passed to |
scale |
Oblique projection foreshortening scale factor.
A (degenerate) |
alpha |
Oblique projection angle (the angle the third axis is projected going off at).
An |
axis |
A Coord3D class object or one that can coerced to one by |
theta |
An |
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 |
xy_shear |
Shear factor: |
xz_shear |
Shear factor: |
yx_shear |
Shear factor: |
yz_shear |
Shear factor: |
zx_shear |
Shear factor: |
zy_shear |
Shear factor: |
x |
A Coord3D object of length one or an object coercible to one by |
transform3d()
User supplied (post-multiplied) affine transformation matrix
.
scale3d()
Scale the x-coordinates and/or the y-coordinates and/or the z-coordinates by multiplicative scale factors.
shear3d()
Shear the x-coordinates and/or the y-coordinates and/or the z-coordinates using shear factors.
translate3d()
Translate the coordinates by a Coord3D class object parameter.
transform3d()
3D affine transformation matrix objects are meant to be
post-multiplied and therefore should not be multiplied in reverse order.
Note the Coord3D class object methods auto-pre-multiply affine transformations
when "method chaining" so pre-multiplying affine transformation matrices
to do a single cumulative transformation instead of a method chain of multiple transformations
will not improve performance as much as as it does in other R packages.
To convert a pre-multiplied 3D affine transformation matrix to a post-multiplied one
simply compute its transpose using t()
. To get an inverse transformation matrix
from an existing transformation matrix that does the opposite transformations
simply compute its inverse using solve()
.
A 4x4 post-multiplied affine transformation matrix with classes "transform3d" and "at_matrix"
p <- as_coord3d(x = sample(1:10, 3), y = sample(1:10, 3), z = sample(1:10, 3)) # {affiner} affine transformation matrices are post-multiplied # and therefore should **not** go in reverse order mat <- transform3d(diag(4L)) %*% rotate3d("z-axis", degrees(90)) %*% scale3d(1, 2, 1) %*% translate3d(x = -1, y = -1, z = -1) p1 <- p$ clone()$ transform(mat) # The equivalent result appyling affine transformations via method chaining p2 <- p$ clone()$ transform(diag(4L))$ rotate("z-axis", degrees(90))$ scale(1, 2, 1)$ translate(x = -1, y = -1, z = -1) all.equal(p1, p2)
p <- as_coord3d(x = sample(1:10, 3), y = sample(1:10, 3), z = sample(1:10, 3)) # {affiner} affine transformation matrices are post-multiplied # and therefore should **not** go in reverse order mat <- transform3d(diag(4L)) %*% rotate3d("z-axis", degrees(90)) %*% scale3d(1, 2, 1) %*% translate3d(x = -1, y = -1, z = -1) p1 <- p$ clone()$ transform(mat) # The equivalent result appyling affine transformations via method chaining p2 <- p$ clone()$ transform(diag(4L))$ rotate("z-axis", degrees(90))$ scale(1, 2, 1)$ translate(x = -1, y = -1, z = -1) all.equal(p1, p2)
sine()
, cosine()
, tangent()
, secant()
, cosecant()
, and cotangent()
are
angle()
aware trigonometric functions that allow for a user chosen angular unit.
sine(x, unit = getOption("affiner_angular_unit", "degrees")) cosine(x, unit = getOption("affiner_angular_unit", "degrees")) tangent(x, unit = getOption("affiner_angular_unit", "degrees")) secant(x, unit = getOption("affiner_angular_unit", "degrees")) cosecant(x, unit = getOption("affiner_angular_unit", "degrees")) cotangent(x, unit = getOption("affiner_angular_unit", "degrees"))
sine(x, unit = getOption("affiner_angular_unit", "degrees")) cosine(x, unit = getOption("affiner_angular_unit", "degrees")) tangent(x, unit = getOption("affiner_angular_unit", "degrees")) secant(x, unit = getOption("affiner_angular_unit", "degrees")) cosecant(x, unit = getOption("affiner_angular_unit", "degrees")) cotangent(x, unit = getOption("affiner_angular_unit", "degrees"))
x |
An angle vector or an object to convert to it (such as a numeric vector) |
unit |
A string of the desired angular unit. Supports the following strings
(note we ignore any punctuation and space characters as well as any trailing
|
A numeric vector
sine(pi, "radians") cosine(180, "degrees") tangent(0.5, "turns") a <- angle(0.5, "turns") secant(a) cosecant(a) cotangent(a)
sine(pi, "radians") cosine(180, "degrees") tangent(0.5, "turns") a <- angle(0.5, "turns") secant(a) cosecant(a) cotangent(a)