Forum: help
Monitor Forum | | RE: how to make this plot with rgl [ Reply ] By: Brian Murphy on 2016-09-26 02:53 | [forum:43804] |
|
The plot is of oil pressure in a hydrodynamic radial bearing. Plots of this type are often used in my field to display results of a finite element analysis. Bearings like this are used in millions of machines, including nearly all internal combustion engines, and that's just the tip of the iceberg. My next task is figuring out how to generate RGL plots from Excel visual basic code. The working environment, including the data to be plotted, is Excel. But Excel can't do decent contour or 3d plots. That's where R and RGL will come to the rescue. |
|
| RE: how to make this plot with rgl [ Reply ] By: Duncan Murdoch on 2016-09-25 23:22 | [forum:43528] |
| I don't find that kind of plot very interesting (it violates physics; what's there to be opaque?), but if you want to develop and submit a function to do it, I'd take a look. | |
| RE: how to make this plot with rgl [ Reply ] By: Brian Murphy on 2016-09-25 21:00 | [forum:43527] |
|
"Ahhh, I see!" said the blind man. The following script does a nice job of making the plot. I think I can see what you mean about round off. library(rgl) userMatrix <- t(matrix(c(0.947,0.32,-0.01156,0,-0.0723,0.249, 0.966,0, 0.312,-0.914, 0.259,0, 0, 0, 0, 1), nrow=4, ncol=4)) windowRect <- c(1009,170,1748,697) zoom <- 0.8 par3d(zoom = zoom, userMatrix = userMatrix, windowRect=windowRect) par3d(FOV=0) x<-scan("x.dat") y<-scan("y.dat") z<-scan("z.dat") zm1<-(z-1.0) persp3d(x,y,z,color="red",front="lines", back="lines",xlab="Axial",ylab="Circumferential",zlab="Pressure") persp3d(x,y,zm1,color="white",lit=FALSE,add=TRUE) Can axis labels be situated along their respective axes as in my sample plot? A more native "hidden" option for rgl would be really nice. I've seen other OpenGL graphics applications that have this. Maybe there is already a feature for this in OpenGL. |
|
| RE: how to make this plot with rgl [ Reply ] By: Brian Murphy on 2016-09-24 15:07 | [forum:43526] |
|
"Ahhh, I see!" said the blind man. The following script does a nice job of making the plot. I think I can see what you mean about round off. library(rgl) userMatrix <- t(matrix(c(0.947,0.32,-0.01156,0,-0.0723,0.249, 0.966,0, 0.312,-0.914, 0.259,0, 0, 0, 0, 1), nrow=4, ncol=4)) windowRect <- c(1009,170,1748,697) zoom <- 0.8 par3d(zoom = zoom, userMatrix = userMatrix, windowRect=windowRect) par3d(FOV=0) x<-scan("x.dat") y<-scan("y.dat") z<-scan("z.dat") zm1<-(z-1.0) persp3d(x,y,z,color="red",front="lines", back="lines",xlab="Axial",ylab="Circumferential",zlab="Pressure") persp3d(x,y,zm1,color="white",lit=FALSE,add=TRUE) Can axis labels be situated along their respective axes as in my sample plot? A more native "hidden" option for rgl would be really nice. I've seen other OpenGL graphics applications that have this. Maybe there is already a feature for this in OpenGL. |
|
| RE: how to make this plot with rgl [ Reply ] By: Duncan Murdoch on 2016-09-24 11:20 | [forum:43524] |
|
That's actually a complicated plot: it has the wireframe look, but it also has an unlit white surface to obscure what's shown behind. It's not easy to do in rgl. I think persp() in base graphics can do things like that more easily. To do it in rgl, you need to plot the surface twice. First plot it with material properties "front" and "back" both set to "lines". This will give you the wireframe, but you'll see through it. To make it opaque, you need to plot a white surface with "lit" set to FALSE. It will hide parts of the wireframe that lie behind. You'll likely see a few artifacts due to rounding error, where the white surface obscures things that are supposed to be visible. Those are hard to avoid; one way is to plot it at a slightly lower position. |
|
| RE: how to make this plot with rgl [ Reply ] By: Brian Murphy on 2016-09-24 05:19 | [forum:43523] |
|
Here are links to the image I'd like to make, and the sample data. www.rotordynamics.org/public/XLHydrodyn3d.png www.rotordynamics.org/public/xyzdata.zip The script below will make a surface plot, but I'd like to get a wireframe plot like the one in the png file. It seems like such a simple thing, but I can't figure out how to get it. windows() library(rgl) setwd("gnuplot") userMatrix <- t(matrix(c(0.947313, 0.3200991,-0.0115599,0,-0.0722910,0.2488211, 0.9658477,0, 0.312043,-0.9141250, 0.2588519,0, 0, 0, 0, 1), nrow=4, ncol=4)) windowRect <- c(1009,170,1748,697) zoom <- 1.0 open3d(zoom = zoom, userMatrix = userMatrix, windowRect=windowRect) x<-scan("x.dat") y<-scan("y.dat") z<-scan("z.dat") persp3d(x,y,z) par3d(FOV=0) |
|
| RE: how to make this plot with rgl [ Reply ] By: Brian Murphy on 2016-09-24 03:28 | [forum:43522] |
|
Thanks for the reply, Duncan. A picture is worth a thousand words. The forum's upload file button seems to not work for me. You should be able to view it from this link: www.rotordynamics.org/public/XLHydrodyn3d.png The data for the plot is here: www.rotordynamics.org/public/xyzdata.zip I have been able to make a similar plot using the following script. This script makes a surface plot instead of a wireframe plot. windows() library(rgl) setwd("gnuplot") userMatrix <- t(matrix(c(0.947313, 0.3200991,-0.0115599,0,-0.0722910,0.2488211, 0.9658477,0, 0.312043,-0.9141250, 0.2588519,0, 0, 0, 0, 1), nrow=4, ncol=4)) windowRect <- c(1009,170,1748,697) zoom <- 1.0 open3d(zoom = zoom, userMatrix = userMatrix, windowRect=windowRect) x<-scan("x.dat") y<-scan("y.dat") z<-scan("z.dat") persp3d(x,y,z) par3d(FOV=0) If you can point me in the right direction for getting a wireframe plot, that would be super. |
|
| RE: how to make this plot with rgl [ Reply ] By: Duncan Murdoch on 2016-09-23 22:32 | [forum:43520] |
|
Can't see any attached picture, but I doubt if I could help you anyway. Please post code that produces the data you want to plot, or there's nothing to work with. BTW, you'll probably get a quicker response on the Stackoverflow.com site, with tag rgl. But feel free to post here if you like. |
|
| how to make this plot with rgl [ Reply ] By: Brian Murphy on 2016-09-23 21:01 | [forum:43519] |
|
Hello. I'm new to R and rgl. I'm stumped trying to make the attached 3d plot. x and y data are vectors, and z is a 2d matrix of "heights" which correspond to the x and y values. Can rgl make this plot? If so, how? If not, is there another package that can do it? I'd like the plot to be interactive so it can be rotated and zoomed. R is really something. But it's so vast that finding something is not a simple task. |
|

