Geometry in affiner

Table of Contents

Angle objects

In {affiner} angles are represented by the angle() class:

library("affiner")
as_angle(90, "degrees") + turns(1)
## <angle<degrees>[1]>
## [1] 450°
is_congruent(degrees(180), radians(pi))
## [1] TRUE
as.numeric(turns(1/3), "radians")
## [1] 2.094395

Trigonometry

{affiner} provides several angle() class aware trigonometric functions:

library("affiner")
sin(2 * pi)
## [1] -2.449294e-16
sine(degrees(360))
## [1] 0
arctangent(x = 0, y = 1)
## <angle<degrees>[1]>
## [1] 90°

2D Coordinates

In {affiner} 2D Coordinates are represented by a Coord2D R6 class:

# Cartesian coordinates
library("affiner")
p <- as_coord2d(x = 1:10, y = 1:10)
print(p)
## <Coord2D[10]>
##        x  y w
##  [1,]  1  1 1
##  [2,]  2  2 1
##  [3,]  3  3 1
##  [4,]  4  4 1
##  [5,]  5  5 1
##  [6,]  6  6 1
##  [7,]  7  7 1
##  [8,]  8  8 1
##  [9,]  9  9 1
## [10,] 10 10 1
p2 <- p$
    clone()$
    scale(x = 0.5)$
    rotate(degrees(90))$
    reflect(as_line2d("y-axis"))$
    translate(as_coord2d(x = 0.5, y = 0.5))$
    print()
## <Coord2D[10]>
##         x   y w
##  [1,] 1.0 1.0 1
##  [2,] 1.5 1.5 1
##  [3,] 2.0 2.0 1
##  [4,] 2.5 2.5 1
##  [5,] 3.0 3.0 1
##  [6,] 3.5 3.5 1
##  [7,] 4.0 4.0 1
##  [8,] 4.5 4.5 1
##  [9,] 5.0 5.0 1
## [10,] 5.5 5.5 1
# Polar coordinates
theta <- degrees(seq(0, 300, by = 60))
radius <- 1
p <- as_coord2d(theta, radius = radius)
is_congruent(as_angle(p), theta) |> all()
## [1] TRUE
is_congruent(abs(p), radius) |> all()
## [1] TRUE

3D Coordinates

In {affiner} 3D Coordinates are represented by a Coord3D R6 class:

# Cartesian coordinates
library("affiner")
p <- as_coord3d(x = 1:10, y = 1:10, z = 1:10)
print(p)
## <Coord3D[10]>
##        x  y  z w
##  [1,]  1  1  1 1
##  [2,]  2  2  2 1
##  [3,]  3  3  3 1
##  [4,]  4  4  4 1
##  [5,]  5  5  5 1
##  [6,]  6  6  6 1
##  [7,]  7  7  7 1
##  [8,]  8  8  8 1
##  [9,]  9  9  9 1
## [10,] 10 10 10 1
p2 <- p$
    clone()$
    scale(z = 0.5)$
    rotate(axis = as_coord3d("z-axis"), theta = degrees(90))$
    reflect(as_plane3d("yz-plane"))$
    shear(xy_shear = 0.5)$
    translate(as_coord3d(x = 0.5, y = 0.5, z = 0.5))$
    print()
## <Coord3D[10]>
##          x    y   z w
##  [1,]  2.0  1.5 1.0 1
##  [2,]  3.5  2.5 1.5 1
##  [3,]  5.0  3.5 2.0 1
##  [4,]  6.5  4.5 2.5 1
##  [5,]  8.0  5.5 3.0 1
##  [6,]  9.5  6.5 3.5 1
##  [7,] 11.0  7.5 4.0 1
##  [8,] 12.5  8.5 4.5 1
##  [9,] 14.0  9.5 5.0 1
## [10,] 15.5 10.5 5.5 1
# Spherical coordinates
inclination <- as_angle(p, type = "inclination")
azimuth <- as_angle(p, type = "azimuth")
radius <- abs(p)
ps <- as_coord3d(azimuth, radius = radius, inclination = inclination)
all.equal(p, ps)
## [1] TRUE
# Cylindrical coordinates
radius <- as_coord2d(p, plane = "xy-plane") |> abs()
pc <- as_coord3d(azimuth, radius = radius, z = p$z)
all.equal(p, pc)
## [1] TRUE

Orthographic/Axonometric and Oblique Projections

{affiner} can project Coord3D objects to Coord2D objects using orthographic/axonometric and oblique projections: