# aabb_piece: Calculate axis-aligned bounding box for set of game pieces In trevorld/piecepack: Board Game Graphics

 aabb_piece R Documentation

## Calculate axis-aligned bounding box for set of game pieces

### Description

Calculate axis-aligned bounding box (AABB) for set of game pieces with and without an “oblique projection”.

### Usage

aabb_piece(
df,
cfg = getOption("piecepackr.cfg", pp_cfg()),
envir = getOption("piecepackr.envir"),
op_scale = getOption("piecepackr.op_scale", 0),
op_angle = getOption("piecepackr.op_angle", 45),
...
)


### 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_cfg object, a list of pp_cfg objects, or a character vector referring to names in envir or a character vector referring to object names that can be retrieved by base::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.5 is the most common scale used in the “cabinet” projection, and 1.0 is the scale used in the “cavalier” projection. op_angle What is the angle of the oblique projection? Has no effect if op_scale is 0. ... Ignored

### 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.

### 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.

### 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)
aabb_piece(df, op_scale = 1, op_angle = 45)
aabb_piece(df, op_scale = 1, op_angle = -90)


trevorld/piecepack documentation built on May 20, 2024, 4:31 a.m.