Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

shadow3d

Project shadows of mesh onto object.


Description

Project a mesh onto a surface in a scene so that it appears to cast a shadow onto the surface.

Usage

shadow3d(obj, mesh, plot = TRUE, up = c(0, 0, 1),
         P = projectDown(up), outside = FALSE,
         ...)

Arguments

obj

The target object which will show the shadow.

mesh

The mesh which will cast the shadow.

plot

Whether to plot the result.

up

Which direction is “up”?

P

The projection to use for draping, a 4x4 matrix. See drape3d for details on how P is used.

outside

Should the function compute and (possibly) plot the region outside of the shadow?

...

Other arguments to pass to filledContour3d, which will do the boundary calculations and plotting.

Details

shadow3d internally constructs a function that is zero on the boundary of the shadow and positive inside, then draws filled contours of that function. Because the function is nonlinear, the boundaries will be approximate, with the best approximation resulting from a large value of filledContour3d parameter minVertices.

If outside = TRUE, the first color used by filledContour3d will indicate the inside of the shadow, and the second color will indicate the exterior.

Value

The returned value from filledContour3d.

Author(s)

Duncan Murdoch

See Also

Examples

open3d()
obj <- translate3d(scale3d(oh3d(), 0.3, 0.3, 0.3), 0,0,2)
shade3d(obj, col = "red")
target <- icosahedron3d()

# We offset the target using polygon_offset = 1 so that the
# shadow on its surface will appear clearly.

shade3d(target, col = "white", polygon_offset = 1)

# minVertices = 1000 leaves noticeable artifacts on the edges
# of the shadow.  A larger value gives a better result, but is
# slower.

# We use facing3d(target) so the shadow and outside part only 
# appear on the upper side of the target

shadow3d(facing3d(target), obj, minVertices = 1000, plot=TRUE,
         col = c("yellow", "blue"), outside = TRUE)

rgl

3D Visualization Using OpenGL

v0.106.8
GPL
Authors
Duncan Murdoch [aut, cre], Daniel Adler [aut], Oleg Nenadic [ctb], Simon Urbanek [ctb], Ming Chen [ctb], Albrecht Gebhardt [ctb], Ben Bolker [ctb], Gabor Csardi [ctb], Adam Strzelecki [ctb], Alexander Senger [ctb], The R Core Team [ctb, cph], Dirk Eddelbuettel [ctb], The authors of Shiny [cph], The authors of knitr [cph], Jeroen Ooms [ctb], Yohann Demont [ctb], Joshua Ulrich [ctb], Xavier Fernandez i Marin [ctb], George Helffrich [ctb], Ivan Krylov [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.