[R] joining two points in rgl
Nair, Murlidharan T
mnair at iusb.edu
Thu Aug 20 16:12:06 CEST 2009
It gave me a the following error
Error in cylinder3d(pts, radius = 0.1, e2 = rbind(c(1, 0, 0), c(1, 0, :
subscript out of bounds
The code I used is below for completeness.
library(rgl)
pts<-structure(list(x = c(-0.975688, -0.975688), y = c(9.258795, -9.258795), z = c(-1.8, 1.8)), .Names = c("x", "y", "z"), class = "data.frame", row.names = c(NA, -2L))
plot3d(pts, col="grey", size=2, box=FALSE, axes=TRUE, type="s",
xlim=c(-5,5), ylim=c(-5,5), zlim=c(-5,5))
text3d(pts[1,],text=c("a"), adj = c(0.5, -1))
text3d(pts[2,],text=c("t"), adj = c(0.5, -1))
shade3d(cylinder3d(pts, radius=0.1, e2=rbind(c(1,0,0),c(1,0,0))), col="red")
Thanks for adj. The rgl package is absolutely wonderful. It is extremely useful to me.
Cheers../Murli
________________________________________
From: Duncan Murdoch [murdoch at stats.uwo.ca]
Sent: Wednesday, August 19, 2009 9:02 PM
To: Nair, Murlidharan T
Cc: r-help at r-project.org
Subject: Re: [R] joining two points in rgl
On 19/08/2009 3:51 PM, Nair, Murlidharan T wrote:
> I tried the following
>
> library(rgl)
> pts<-structure(list(x = c(-0.975688, -0.975688), y = c(9.258795, -9.258795), z = c(-1.8, 1.8)), .Names = c("x", "y", "z"), class = "data.frame", row.names = c(NA, -2L))
>
> plot3d(pts$x,pts$y,pts$z, col="grey", size=2, box=FALSE, axes=TRUE, type="s")
> lines3d(pts$x,pts$y,pts$z, col="black", lwd=5)
> x1<--0.975688
> y1<-9.258795
> z1<--1.8+0.2
> x2<--0.975688
> y2<--9.258795
> z2<-1.8+0.2
> text3d(x1,y1,z1,text=c("a"))
> text3d(x2,y2,z2,text=c("t"))
>
> cylinder3d(c(x1,y1,z1),c(x2,y2,z2))
The first argument should be a matrix giving all the coordinates of the
centres.
>
>
> 1> I tried the above and could not get it to work. I did not understand how to give the Frenet coordinates. Can you give me some tip here please?
There was actually a typo in the handling of e2, but with that fixed,
this works:
plot3d(pts, col="grey", size=2, box=FALSE, axes=TRUE, type="s",
xlim=c(-5,5), ylim=c(-5,5), zlim=c(-5,5))
text3d(pts[1,],text=c("a"), adj = c(0.5, -1))
text3d(pts[2,],text=c("t"), adj = c(0.5, -1))
shade3d(cylinder3d(pts, radius=0.1, e2=rbind(c(1,0,0),c(1,0,0))), col="red")
It's not perfect, because it draws a cylinder with a circular cross
section, but the original plot has very uneven scaling. That's why I
added the xlim, ylim, and zlim: to get equal coordinates in all axes.
>
> 2> Is there a better way of writing the text than what I have done above? Can I make the spheres transparent so that if I write the text at the exact same coordinate of the sphere the text is above the sphere and can be seen?
You can use adj = c(0.5, -1) in the text3d calls to place the text above
the point, as I did above.
Duncan Murdoch
>
>
> Thanks ../Murli
>
>
>
>
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Nair, Murlidharan T
> Sent: Friday, August 14, 2009 4:14 PM
> To: Duncan Murdoch
> Cc: r-help at r-project.org
> Subject: Re: [R] joining two points in rgl
>
>> Thanks, for lwd. I could not find rgl 0.85. The latest one I saw was 0.84. Can you tell me where I can download it from?
>>
>
> It's on r-forge.r-project.org
>
>> Also, is there a curve3d? I need to join two points in 3d smoothly.
>>
> No, though par3dinterp could probably be faked into doing that.
>
> Duncan Murdoch
>
>
>
>
> Thanks ../Murli
>
>
> -----Original Message-----
> From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca]
> Sent: Thursday, August 13, 2009 8:24 PM
> To: Nair, Murlidharan T
> Cc: r-help at r-project.org
> Subject: Re: [R] joining two points in rgl
>
> Nair, Murlidharan T wrote:
>> Hi!!
>>
>> I need to draw a cylinder/tube joining two points. I am trying to make something presentable, I have been able to do it using lines3d. But is it possible to
>> increase the thickness of the lines? The size parameter does not work. Does any one have any suggestions?
>>
> There's a new function cylinder3d (in rgl 0.85) that probably does
> exactly what you want, but lwd is the parameter that controls line width.
>
> Duncan Murdoch
>> Thanks ../Murli
>>
>> library(rgl)
>> pts<-structure(list(x = c(-0.975688, -0.975688), y = c(9.258795, -9.258795
>> ), z = c(-1.8, 1.8)), .Names = c("x", "y", "z"), class = "data.frame", row.names = c(NA,
>> -2L))
>>
>> plot3d(pts$x,pts$y,pts$z, col="grey", size=2, box=FALSE, axes=FALSE, type="s")
>> lines3d(pts$x,pts$y,pts$z, col="grey", size=2)
>>
>> ______________________________________________
>> 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.
>>
>
> ______________________________________________
> 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