File: widgetlighting.R

package info (click to toggle)
rgl 1.3.31-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,984 kB
  • sloc: cpp: 23,234; ansic: 7,462; javascript: 6,121; sh: 3,555; makefile: 2
file content (31 lines) | stat: -rw-r--r-- 928 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
library(rgl)

## a function to plot good-looking spheres

sphere1.f <- function(x0 = 0, y0 = 0, z0 = 0, r = 1, n = 101, ...){
  f <- function(s,t){ 
    cbind(   r * cos(t)*cos(s) + x0,
             r *        sin(s) + y0,
             r * sin(t)*cos(s) + z0)
  }
  
  persp3d(f, slim = c(-pi/2,pi/2), tlim = c(0, 2*pi), n = n, add = T,  ...)
}

## a set of 3D coordinates for my spheres

agg <- as.data.frame(list(x = c(-0.308421860438279, -1.42503395393061), y = c(0.183223776337368, 1.69719822686475), z = c(-0.712687792799106, -0.0336746884947792)))

open3d()

##material and light effects for the spheres

clear3d(type = "lights")
light3d(theta = -30, phi = 60, viewpoint.rel = TRUE, ambient = "#FFFFFF", diffuse = "#FFFFFF", specular = "#FFFFFF", x = NULL, y = NULL, z = NULL)

## plot the spheres.
sphere <- sphere1.f(r=0.5)
sprites <- sprites3d(agg, radius = 0.5, shapes = sphere,
          rotating = TRUE)

rglwidget()