3D Model Using the rgl Package

[This article was first published on Stats and things, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

A while back, I had a unique opportunity to work with some very talented interns for the summer while I was working at Allstate insurance. Without giving away details of the project that Allstate may prefer to keep secret, let’s just say that we had access to a laser range finder, and were testing it on a cardboard cutout. The laser range finder would give angle and distance in a fan shape directly in front of it. It’s used in robotics to detect obstacles and whatnot. We mounted the scanner on a platform and moved it vertically. That way, we could take a fan shape of measurements incrementally moving up and down giving a 3D view of the target.

The data file was great, but we needed a way to visually inspect the data to check that the trig the interns had to do to get x,y,z data from the angle, angle, distance raw data was correct. So, I fired up R, found the rgl package, and got to work.

There’s really not much to the code, first I read in the data. They gave me a 2D matrix of z values. I created some dummy x and y data, fitted it to some colors, smoothed out some errant laser readings and ran the viewer…


It opens a viewer that you can zoom, tilt, and pan.


There are options to adjust the artificial lighting, the colors, and a bunch of other things, but as you can see, it came out fairly well. This was a 3d cardboard “car” taped to a wall. You can even see evidence of the tape coming out of the roof and windshield.

The code and data are on github here… https://github.com/corynissen/3D_model_demo

follow me on twitter… https://twitter.com/corynissen


To leave a comment for the author, please follow the link and comment on their blog: Stats and things.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)