[R] how to draw manifold?

Carl Witthoft carl at witthoft.com
Sun Nov 21 21:02:35 CET 2010


Thanks, Dennis.   Here's an enhanced version:

  z <- seq(-10, 10, 0.1)
   zm<-cbind(z,z,z,z,z,z,z,z,z,z)

ym<-matrix(nr=201,nc=10)
for (i in seq(1,201)) {
	for (j in seq(1,10)) ym[i,j]<-j/10*sin(zm[i,1])}

xm<-matrix(nr=201,nc=10)
for (i in seq(1,201)) {
	for (j in seq(1,10)) xm[i,j]<-j/10*cos(zm[i,1])}

	
scatterplot3d(as.vector(t(xm)), as.vector(t(ym)), as.vector(t(zm)), main 
= 'Helix', pch = ".",type='l')


 From there I can draw a few helical lines by modifying your original 
code (for different radii), and end up with a pretty decent "mesh surface."

Carl


On 11/20/10 12:03 PM, Dennis Murphy wrote:
> Hi:
>
> Here's an example stolen out of the scatterplot3d package vignette (p. 9):
>
> library(scatterplot3d)
> z<- seq(-10, 10, 0.01)
> x<- cos(z)
> y<- sin(z)
> scatterplot3d(x, y, z, highlight.3d = TRUE, col.axis = 'blue',
>                col.grid = 'lightblue', main = 'Helix', pch = 20)
>
> HTH,
> Dennis
>
> On Sat, Nov 20, 2010 at 8:29 AM, Carl Witthoft<carl at witthoft.com>  wrote:
>
>> Hi,
>> I need some help either in how to configure variables for wireframe(), or
>> some suggestions as to other graphics commands to use for plotting a 2-D
>> manifold in 3-D space.
>>
>> Here is an example I tried (in the hopes that it would plot a helical line)
>> :
>>
>> xsp<-matrix(c(cos(seq(0,80)/5)),9,9)
>> ysp<-matrix(c(sin(seq(0,80)/5)),9,9)
>> zsp<-matrix(c((seq(0,80)/20)),9,9)
>> wireframe(zsp~xsp*ysp)
>>
>> The resulting plot looks vaguely like a helix, but not right.  And if I
>> change my variables' dimensions to c(3,27) it looks "better," but if the
>> dims are c(1,81), nothing gets plotted.
>>
>> So: is there a way to control which points are connected by lines in
>> wireframe()?  Or is there a more appropriate way to provide a plotting
>> program with sets of coordinates in 3-space?
>>
>> My primary goal is to be able to plot surfaces, not just a line as in my
>> sample code.  For example, I might expand the data above to represent points
>> on a 'ribbon' helix.
>>
>> Thanks for yr. help -- feel free to point me to help files for existing
>> packages or plotting routines.
>>
>> Carl
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>



More information about the R-help mailing list