3D Model Using the rgl Package

April 25, 2013

(This article was first published on Stats and things, and kindly contributed to R-bloggers)

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


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)