sphere3js: Add a sphere of defined radius to a data3js object

View source: R/3JSobjects.R

sphere3jsR Documentation

Add a sphere of defined radius to a data3js object

Description

Unlike points3js, where geometric points can also be represented as spheres, this adds sphere that is sized with respect to the actual dimensions of the plotting space (and so if aspect ratios differ for each axis may not actually appear sphere-like).

Usage

sphere3js(data3js, x, y, z, radius, col = "black", highlight, ...)

Arguments

data3js

The data3js object

x

x coordinate of the sphere center

y

y coordinate of the sphere center

z

z coordinate of the sphere center

radius

sphere radius

col

color

highlight

highlight attributes (see highlight3js())

...

other arguments to pass to material3js()

Value

Returns an updated data3js object

See Also

Other plot components: arrows3js(), axis3js(), box3js(), grid3js(), legend3js(), light3js(), lines3js(), mtext3js(), points3js(), segments3js(), shape3js(), surface3js(), text3js(), triangle3js()

Examples

# Setup base plot
p <- plot3js(
  xlim = c(-10, 10),
  ylim = c(-5, 5),
  zlim = c(-8, 8)
)

# Add sphere (this will look distorted because of axis scaling)
p <- sphere3js(
  data3js = p,
  0, 0, 0,
  radius = 5,
  col = "green"
)

r3js(p, zoom = 2.5)

# Setup base plot with equal aspect ratio
p <- plot3js(
  xlim = c(-10, 10),
  ylim = c(-5, 5),
  zlim = c(-8, 8),
  aspect = c(1, 1, 1)
)

# Add sphere (fixed aspect ratio now makes the sphere look spherical)
p <- sphere3js(
  data3js = p,
  0, 0, 0,
  radius = 5,
  col = "green"
)

r3js(p, zoom = 2)


r3js documentation built on March 31, 2023, 7:23 p.m.