Thursday, April 25, 2013

3D Model Using the rgl Package

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...

follow me on twitter...

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.