Jeromy Anglim
Jeromy Anglim

Reputation: 34907

How to plot a three dimensional sphere in R based on center and radius?

How can one plot a sphere in R by providing a center point and a radius?

For example, something like this:

sphere_3d(center=c(1,1,1), r=2))

The plot would appear on a three dimensional coordinate system.

Upvotes: 3

Views: 10298

Answers (3)

Jeromy Anglim
Jeromy Anglim

Reputation: 34907

Adapted from @mdsummer's answer, this also adds axes.

library(rgl)
open3d()                                   # create new plot
spheres3d(x = 1, y = 1, z = 1, radius = 1) # produce sphere
axes3d()                                   # add x, y, and z axes

Upvotes: 3

mdsumner
mdsumner

Reputation: 29477

Try spheres3d in the rgl package for an interactive plot:

library(rgl)
spheres3d(x = 1, y = 1, z = 1, radius = 1)

There are many other ways, so what's going to be useful needs more input.

Upvotes: 7

Alex Reynolds
Alex Reynolds

Reputation: 96937

Take a look at the rgl package for making 3D plots.

Upvotes: 1

Related Questions