Learn R Programming

spanner (version 1.0.2)

create_rotation_gif: Create animated GIF of rotating 3D point cloud

Description

Generates a 360-degree rotating animation of a LAS point cloud using rgl and saves it as an animated GIF.

Usage

create_rotation_gif(
  las,
  output_path = "pointcloud_rotation.gif",
  duration = 12,
  rpm = 5,
  background = "white",
  axis = "z",
  show_axis = TRUE,
  show_legend = TRUE,
  screen_size = c(800, 600),
  overwrite = FALSE
)

Value

Character string of the output file path (invisible)

Arguments

las

LAS object to visualize. Should have R, G, B fields for color.

output_path

Character string specifying output GIF file path. Default is "pointcloud_rotation.gif".

duration

Numeric duration of the animation in seconds. Default is 12.

rpm

Numeric rotations per minute for the spin. Default is 5.

background

Character string specifying background color. Default is "white".

axis

Character specifying rotation axis: "z" for vertical rotation (default), "x" for horizontal rotation, "y" for front-to-back rotation.

show_axis

Logical whether to show axes. Default is TRUE.

show_legend

Logical whether to show legend. Default is TRUE.

screen_size

Numeric vector of length 2 specifying window dimensions as c(width, height). Default is c(800, 600).

overwrite

Logical whether to overwrite existing output file. Default is FALSE.

Details

This function creates a smooth 360-degree rotation animation by:

  • Plotting the point cloud using lidR's plot function with RGB colors

  • Using rgl's movie3d and spin3d to create smooth rotation

  • Saving the result as an animated GIF

The rotation speed is controlled by the rpm (rotations per minute) parameter. The total duration determines how long the animation will be.

Requires the rgl package and lidR for plotting.

Examples

Run this code
# \donttest{
# Load example LAS file
LASfile <- system.file("extdata", "ALS_Clip.laz", package="spanner")
las <- readLAS(LASfile)

# Create basic rotation GIF with attribute coloring
las_colored <- colorize_las(las, method="attr", attribute_name="Z")
create_rotation_gif(las_colored, output_path=tempfile(fileext = ".gif"))

# High quality with specific settings
create_rotation_gif(las_colored,
                    output_path=tempfile(fileext = ".gif"),
                    duration=15,
                    rpm=10,
                    background="black",
                    show_axis=FALSE,
                    show_legend=FALSE)

# Rotate around X axis for side-to-side view
create_rotation_gif(las_colored, output_path=tempfile(fileext = ".gif"), axis="x")
# }

Run the code above in your browser using DataLab