Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi, just a quick question: does anyone know of any modules that will allow points to be plotted in 3 dimensions? I've already tried searching CPAN, and the closest thing seems to be Chart::Graph::Xrt3d, however that requires xrt3d, which appears to be commercial software. Are there any alternatives here?
Re: 3D Point Plotting
by AbigailII (Bishop) on May 28, 2002 at 16:29 UTC

 [reply] [Watch: Dir/Any] 
Re: 3D Point Plotting
by FoxtrotUniform (Prior) on May 28, 2002 at 01:43 UTC

does anyone know of any modules that will allow points
to be plotted in 3 dimensions?
You might try the OpenGL set of
modules, even though they're massive overkill for simply
plotting 3d points.
Update: If you're interested, the definitive
OpenGL site is http://www.opengl.org.

The hell with paco, vote for Erudil!
:wq
 [reply] [Watch: Dir/Any] 

Yeah, OpenGL would be crazy for use in CGI (looking to export the graph as png or such)... heh. And I tried looking at GD::Graph3d... it doesn't allow point plotting, just "3d" bar graph, "3d" pie graph, and a line graph with depth... not useful, unfortunately.
 [reply] [Watch: Dir/Any] 
Re: 3D Point Plotting
by Merlin42 (Friar) on May 28, 2002 at 16:12 UTC

I know you asked for a module, but this can be done very simply .. as long as you only want to do simple stuff :).
If you are only interested in doing 3d points and have a static projective camera pointed along the Z axis then you can use the old 'divide by Z' trick. This is what is used in the classic 'flying stars/windows' screen saver.
Lets say you are interested in veiwing some points inside a 3d cube of dimensions x1 to x2 by y1 to y2 by z1 to inf
 throw out points outside this box (cull/clip)
 divide by Z (projection)
 scale to viewport
ie
for each point x,y,z
x2d=x/z; y2d=y/z
Xviewport=(x2dx1/z1)*(x2x1)/z1*image_width
Yviewport=(y2dy1/z1)*(y2y1)/z1*image_height
plot Xviewport,Yviewport into the bitmap
NOTE: This is off the top of my head so it might be utter jiberish
NOTE: You could add one step b4 the cull/clip to transform your points so that they can be viewed along the z axis. This can be done w/ a 3x3 matrix multiply and a vector add(or with a 4x4 matrix mult ala OpenGL).
NOTE: If you prescale Z by some factor you can get different "zooms"
NOTE: If you want an orthographic projection, more like engineering diagrams/bluerpints then just skip all the divides and just thow away Z.  [reply] [Watch: Dir/Any] 
Re: 3D Point Plotting
by cjf (Parson) on May 28, 2002 at 00:21 UTC

 [reply] [Watch: Dir/Any] 

If I remember correctally, GD::Graph3d really only gives charts a '3d' appearance, I might be wrong though, as I haven't ever actually tried to use it. (I do use GD::Graph and GD though.)
"Weird things happen, get used to it."
Flame ~ Lead Programmer: GMS
 [reply] [Watch: Dir/Any] 
Re: 3D Point Plotting
by rbc (Curate) on May 28, 2002 at 17:08 UTC

You might want to see if this is what you are looking for
simple 3D graphics
The script in this link demonstrates how to draw a cube
and perform rotation and translations on it.  [reply] [Watch: Dir/Any] 

rbc, thanks, but that script works with Tk... which isn't really applicable in the context of CGI, as far as I know... gnuplot looks like it might do the trick, but I'll have to play around with it a bit more. And as to your suggestion, Merlin42, very interesting but a bit beyond me, for now (still interested though). I figure I might as well explain the point of all this anyways: I'm going to be having as data a large number of RGB values, and am trying to plot them all in a 3d cubic space, so one can visually see clustering of the colors. For now I'll try gnuplot some more, but any other suggestions would be great. Thanks.
 [reply] [Watch: Dir/Any] 

Ok first I want to apoligize for my previous post ... the formulas are fscked up. Rather than try to fix them for the general case Ill give you a simple version that will work for your specific case.
for each point R,G,B contained in (0,1)x(0,1)x(0,1):
X=(R0.5)/(B+1)*IMAGE_WIDTH + IMAGE_WIDTH/2
Y=(G0.5)/(B+1)*IMAGE_HEIGHT + IMAGE_HEIGHT/2
You can change the 1 to 'dolly' the camera back and forth.
Just swap the variables to view along a different color axis.
To view not along a color axis you need to rotate the points before hand. eg
R'= R*cos(theta)+G*sin(theta)
G'=R*sin(theta)+G*cos(theta)
B'= B
to rotate about the B axis
R'= R
G'= G*cos(theta)+B*sin(theta)
B'=G*sin(theta)+B*cos(theta)
to rotate about the R axis, and
R'=R*cos(theta)B*sin(theta)
G'=G
B'=R*sin(theta)+B*cos(theta)
to rotate about the G axis
Geez I can't get anything right...maybe this really isnt as simple as I said :). The formulas should now map the entire RGB space into the image ... if you rotate the space then the corners will not be visible ... fix this by increasing the value added to the denomiator.  [reply] [Watch: Dir/Any] 


Others admiring the Monastery: (5) As of 20240305 14:25 GMT
