|
|
"Daniel C. Bastos" <dba### [at] yahoocombr> wrote:
> Hi there. I'm interested in plotting some graphs in povray. I have been
> reading the documentation in the help file, but it is not going torwards
> telling me how to plot, say, x = cos(t), y = cos(t), z = t. Could
> someone point me in some direction where I can learn the basics of
> getting some parametric equations plotted?
Strictly speaking, POV-Ray is a program for creating 3-D images, so there aren't
really 'plot' functions. But that's certainly not to say you can't plot things.
On the contrary, it's not too hard and very, very flexible. The most basic way
is just to draw a set of cylinders between consecutive points. This can be done
with a function or a macro, as defined below. If there's a gap you'll see it
though, so you can add a sphere at each point too. Of course you have to add a
camera and lights to make it a true 3-D scene, but that's pretty
straightforward. Rather than describe it all, you can just test out the code
below and modify it to your needs. Text and ticmarks could be added too.
#include "colors.inc"
camera{
location <2,3.5,-5>
angle 50
look_at <0,0,0>
}
//Fill light:
light_source{
<15,25,-15>
rgb 0.3
shadowless
}
//Light to case shadows:
light_source{
<15,25,-15>
rgb 0.7
area_light 4*x,4*y,8,8
circular
orient
jitter
adaptive 2
}
//Checkered plane for reference:
plane{y,-2
pigment{
checker rgb 0.6, rgb 0.7
}
finish{
ambient 0
diffuse 1.0
}
}
//Specify the radius of all the 'lines'
#declare rad=0.03;
//draw some axes:
cylinder{-100*x,100*x,rad/2 pigment{rgb x} no_shadow}
cylinder{-100*y,100*y,rad/2 pigment{rgb y} no_shadow}
cylinder{-100*z,100*z,rad/2 pigment{rgb z} no_shadow}
//Function to plot:
#macro func(tv)
// < x, y, z > =
#local pd=15.0;
#local amp=0.3;
< cos(tv)+amp*cos(pd*tv)*cos(tv), //x
sin(tv)+amp*cos(pd*tv)*sin(tv), //y
amp*sin(pd*tv)> //z
#end
//Store the old point and calculate a new point,
//then connect them with a cylinder and a sphere too,
//just in case there is a sharp angle.
#declare tmin = 0.0;
#declare tmax = 2.0*pi;
#declare dt = 0.005;
union{
#declare tv=tmin+dt;
#declare tv2=tmin;
#declare xp2=func(tv2);
#while(tv<tmax+dt/2)
#declare xp=func(tv);
union{
cylinder{xp,xp2,rad}
sphere{xp,rad}
#declare tn=(tv-tmin)/(tmax-tmin);
pigment{rgbft CHSV2RGB(<240.0-240.0*tn,1.0,1.0>)}
}
#declare xp2=xp;
#declare tv2=tv;
#declare tv=tv+dt;
#end
pigment{rgb 1}
finish{
ambient 0
diffuse 1.0
}
}
Post a reply to this message
|
|