## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 6,
                      dpi = 96, out.width = "100%")
# on Linux the default X11 png device cannot draw semi-transparent fills; use cairo there
if (Sys.info()[["sysname"]] == "Linux" && isTRUE(capabilities("cairo"))) knitr::opts_chunk$set(dev.args = list(png = list(type = "cairo")))
library(forensicR)
set.seed(2026)

## ----impact-------------------------------------------------------------------
impact_angle(width = c(9.1, 6.0), length = c(9.3, 12.5), se = 0.5)

## ----rod----------------------------------------------------------------------
t_rod <- trajectory_from_angles(anchor = c(2.0, 5.0, 1.35),
                                azimuth_deg = 352, vertical_deg = -3,
                                se_azimuth = 5, se_vertical = 5, id = "D2 rod")
t_rod

## ----twopt--------------------------------------------------------------------
t_2pt <- trajectory_2pt(p1 = c(3.4, 4.2, 1.20), p2 = c(3.73, 4.92, 1.10),
                        se_position = 0.01, id = "D3 two-point")
t_2pt

## ----ellipse------------------------------------------------------------------
t_ell <- trajectory_from_defect(anchor = c(1.2, 5.0, 1.60), width = 9.3, length = 10.0,
                                major_axis_deg = 85, wall_azimuth_deg = 180,
                                came_from = "right", se = 0.5, se_orientation = 5,
                                id = "D1 ellipse")
t_ell
trajs <- list(t_rod, t_2pt, t_ell)
trajectory_table(trajs)[, c("id", "method", "azimuth_deg", "se_azimuth", "vertical_deg", "se_vertical")]

## ----plan---------------------------------------------------------------------
walls <- rbind(room_rect(0, 0, 6, 5), opening(2.5, 0, 3.5, 0, "door"))
plot_trajectories(trajs, view = "plan", walls = walls, back = 6, convergence = TRUE)

## ----elev, fig.height = 3.4---------------------------------------------------
plot_trajectories(trajs, view = "elevation", back = 6)

## ----origin-------------------------------------------------------------------
origin_zone(t_rod, heights = c(standing = 1.5, kneeling = 1.0, prone = 0.3),
            max_distance = 12)

## ----converge-----------------------------------------------------------------
ix <- intersect_trajectories(t_rod, t_2pt)
ix$point
ix$miss_distance
ix$behind_both
ix$summary

## ----obstructions-------------------------------------------------------------
furn <- rbind(along_wall(walls, "north", from = 3.4, length = 2.1, depth = 0.9, id = "Sofa", type = "sofa"),
              furniture("Floor lamp", "box", x = 1.95, y = 3.85, width = 0.3, depth = 0.3, height = 1.7))
trajectory_obstructions(trajs, furn, back = 6)

## ----path---------------------------------------------------------------------
seg_in  <- trajectory_from_angles(anchor = c(4.0, 2.6, 0.5), azimuth_deg = 69, vertical_deg = -30,
                                  id = "D4 into table")
seg_out <- trajectory_2pt(p1 = c(4.25, 3.1, 0.45), p2 = c(4.9, 5.0, 0.2), se_position = 0.01,
                          id = "D4 to wall")
shot4 <- trajectory_path(seg_in, seg_out, id = "Shot 4")
shot4
path_deflections(shot4)[, c("joint", "deflection_deg", "lower", "upper", "miss_in", "miss_out", "joint_source")]

## ----assumed------------------------------------------------------------------
shot5 <- trajectory_path(seg_in,
                         assumed_segment(seg_in, joint = c(4.25, 3.1, 0.45), length = 2.5,
                                         se_deflection = 10, id = "after table (assumed)"),
                         id = "Shot 5")
trajectory_table(shot5)[, c("id", "path", "segment", "assumed", "method")]
plot_trajectories(list(shot4, shot5), view = "plan", walls = walls,
                  furniture = furniture("Coffee table", "table", x = 3.9, y = 2.6, width = 1.0, depth = 0.5),
                  back = 4)

## ----fig3d, echo = FALSE, fig.cap = "The three trajectories of section 2 rendered to scale: rods with arrowheads at the defects, wireframe cones for the angular uncertainty, floor grid with numbered axes."----
knitr::include_graphics("figures/shooting-dollhouse.png")

## ----render, eval = FALSE-----------------------------------------------------
# render_scene_3d(walls, NULL, trajs, file = "shooting.png", view = "dollhouse")

