Calculate axis-aligned bounding box (AABB) for set of game pieces with and without an “oblique projection”.
Arguments
- df
A data frame of game piece information with (at least) the named columns “piece_side”, “x”, and “y”.
- cfg
Piecepack configuration list or
pp_cfgobject, a list ofpp_cfgobjects, or a character vector referring to names inenviror a character vector referring to object names that can be retrieved bybase::dynGet().- envir
Environment (or named list) containing configuration list(s).
- op_scale
How much to scale the depth of the piece in the oblique projection (viewed from the top of the board).
0(the default) leads to an “orthographic” projection,0.5is the most common scale used in the “cabinet” projection, and1.0is the scale used in the “cavalier” projection.- op_angle
What is the angle of the oblique projection? Has no effect if
op_scaleis0.- ...
Ignored
Value
A named list of ranges with five named elements x, y, and z for
the axis-aligned bounding cube
in xyz-space plus x_op and y_op for the axis-aligned bounding box
of the “oblique projection” onto the xy plane.
Details
The “oblique projection” of a set of \((x,y,z)\) points onto the xy-plane is \((x + \lambda * z * cos(\alpha), y + \lambda * z * sin(\alpha))\) where \(\lambda\) is the scale factor and \(\alpha\) is the angle.
Examples
df_tiles <- data.frame(piece_side="tile_back", x=0.5+c(3,1,3,1), y=0.5+c(3,3,1,1),
suit=NA, angle=NA, z=NA, stringsAsFactors=FALSE)
df_coins <- data.frame(piece_side="coin_back", x=rep(4:1, 4), y=rep(4:1, each=4),
suit=1:16%%2+rep(c(1,3), each=8),
angle=rep(c(180,0), each=8), z=1/4+1/16, stringsAsFactors=FALSE)
df <- rbind(df_tiles, df_coins)
aabb_piece(df, op_scale = 0)
#> $x
#> [1] 0.5 4.5
#>
#> $y
#> [1] 0.5 4.5
#>
#> $z
#> [1] 0.000 0.375
#>
#> $x_op
#> [1] 0.5 4.5
#>
#> $y_op
#> [1] 0.5 4.5
#>
aabb_piece(df, op_scale = 1, op_angle = 45)
#> $x
#> [1] 0.5 4.5
#>
#> $y
#> [1] 0.5 4.5
#>
#> $z
#> [1] 0.000 0.375
#>
#> $x_op
#> [1] 0.500000 4.676777
#>
#> $y_op
#> [1] 0.500000 4.676777
#>
aabb_piece(df, op_scale = 1, op_angle = -90)
#> $x
#> [1] 0.5 4.5
#>
#> $y
#> [1] 0.5 4.5
#>
#> $z
#> [1] 0.000 0.375
#>
#> $x_op
#> [1] 0.5 4.5
#>
#> $y_op
#> [1] 0.25 4.50
#>