POV-Ray : Newsgroups : povray.newusers : povray and 3D graphs Server Time
1 Nov 2024 14:17:48 EDT (-0400)
  povray and 3D graphs (Message 1 to 10 of 17)  
Goto Latest 10 Messages Next 7 Messages >>>
From: Daniel C  Bastos
Subject: povray and 3D graphs
Date: 16 Apr 2008 19:59:01
Message: <slrng0cijt.fin.dbast0s@yahoo.com.br>
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?

I understand some softwares specially written for this purpose are
easier to use, but as I'd like to do some povraying in general and I
often would like to plot some equations and vectors et cetera, I thought
of using povray for my current needs. 

Also, the quality of the images of povray are great, and using it for
plotting equations seems to be more educational; I need to think about
the curves and where I want look at them from, which seems like a good
idea. Thanks for any pointers.


Post a reply to this message

From: triple r
Subject: Re: povray and 3D graphs
Date: 16 Apr 2008 21:25:01
Message: <web.4806a5dfc9f0a145ae42298f0@news.povray.org>
"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

From: Warp
Subject: Re: povray and 3D graphs
Date: 16 Apr 2008 21:34:04
Message: <4806a90b@news.povray.org>
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?

  That depends a lot on what is it exactly that you want to plot.
Eg. plotting a surface is completely different from plotting a curve.
Your example seems to be a curve.

  There is no direct support for curves per se, but you can approximate
one by, for example, creating tiny cylinders along the curve, for example
like this:

#declare X = function(T) { sin(T) };
#declare Y = function(T) { cos(T) };
#declare Z = function(T) { T };

#declare CylRadius = .05;
#declare MinT = 0;
#declare MaxT = 2*pi;
#declare Steps = 100;

union
{ #declare Ind = 0;
  #while(Ind < Steps)
    #declare T1 = MinT + (MaxT-MinT)*Ind/Steps;
    #declare T2 = MinT + (MaxT-MinT)*(Ind+1)/Steps;
    #declare P1 = <X(T1), Y(T1), Z(T1)>;
    #declare P2 = <X(T2), Y(T2), Z(T2)>;
    sphere { P1, CylRadius }
    cylinder { P1, P2, CylRadius }
    #declare Ind = Ind+1;
  #end

  pigment { rgb x } finish { specular .5 }
}

camera { location -z*5 look_at 0 angle 35 }
light_source { <100, 200, -300>, 1 }
plane { y, -1.5 pigment { checker rgb 1, rgb .5 scale 10 } }


-- 
                                                          - Warp


Post a reply to this message

From: Daniel C  Bastos
Subject: Re: povray and 3D graphs
Date: 17 Apr 2008 01:42:36
Message: <slrng0d6o7.fin.dbast0s@yahoo.com.br>
In article <4806a90b@news.povray.org>,
Warp wrote:

> 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?
>
>   That depends a lot on what is it exactly that you want to plot.
> Eg. plotting a surface is completely different from plotting a curve.
> Your example seems to be a curve.

I see. As it is not obvious for a beginner how to plot, I'll stick to
curves for now. I already imagined that some construction would be
necessary and I'm okay with that. I think I even prefer it like that, so
that as I get to plot one curve, I get to plot any other one, I guess,
as the method seems to be similar.

My question for now would be how to figure out how to rotate the
picture. I can see the helix as if I'm looking at it from the top,
although I look at the plane as if I'm standing on it facing the helix. 

What I would like to do on your code is to keep the plane where it is
--- that would be my xy-plane --- and make the helix start from the
plane and spiral up, because that's how this helix should be as x varies
according to cos(t) and y to sin(t) and z = t. That is, while x and y
circle around, z keeps on going up (or down.)

So what I think it's happening here is that while I keep on thinking on
the xyz-axis as I do, the povray puts the z axis as going from outside
my screen into it. So if I swap y and z I should get what I'd like, and
apparently I do.

I also took your code and plotted it from -25pi to 25pi and it spirals
just right. Cool. I'm impressed. This is what I'm looking for. Thanks
for the introduction.

>   There is no direct support for curves per se, but you can approximate
> one by, for example, creating tiny cylinders along the curve, for example
> like this:
>
> #declare X = function(T) { sin(T) };
> #declare Y = function(T) { cos(T) };
> #declare Z = function(T) { T };
>
> #declare CylRadius = .05;
> #declare MinT = 0;
> #declare MaxT = 2*pi;
> #declare Steps = 100;
>
> union
> { #declare Ind = 0;
>   #while(Ind < Steps)
>     #declare T1 = MinT + (MaxT-MinT)*Ind/Steps;
>     #declare T2 = MinT + (MaxT-MinT)*(Ind+1)/Steps;
>     #declare P1 = <X(T1), Y(T1), Z(T1)>;
>     #declare P2 = <X(T2), Y(T2), Z(T2)>;
>     sphere { P1, CylRadius }
>     cylinder { P1, P2, CylRadius }
>     #declare Ind = Ind+1;
>   #end
>
>   pigment { rgb x } finish { specular .5 }
> }
>
> camera { location -z*5 look_at 0 angle 35 }
> light_source { <100, 200, -300>, 1 }
> plane { y, -1.5 pigment { checker rgb 1, rgb .5 scale 10 } }


Post a reply to this message

From: Tim Attwood
Subject: Re: povray and 3D graphs
Date: 17 Apr 2008 05:54:34
Message: <48071e5a@news.povray.org>
> What I would like to do on your code is to keep the plane where it is
> --- that would be my xy-plane --- and make the helix start from the
> plane and spiral up, because that's how this helix should be as x varies
> according to cos(t) and y to sin(t) and z = t. That is, while x and y
> circle around, z keeps on going up (or down.)

You can rotate unions like any other object, there's a good tutorial in
the manual too.

> So what I think it's happening here is that while I keep on thinking on
> the xyz-axis as I do, the povray puts the z axis as going from outside
> my screen into it. So if I swap y and z I should get what I'd like, and
> apparently I do.

POV uses a left handed coordinate system, like if you point with
your left hand, thumb up is y, pointer finger in is z, and middle
finger right is x. Rotations are the same way, if you trace from your
left palm looping around your fingers that is the direction of rotation
used for each axis.

> I also took your code and plotted it from -25pi to 25pi and it spirals
> just right. Cool. I'm impressed. This is what I'm looking for. Thanks
> for the introduction.

Yeah, Warp knows his stuff =)
I fiddled with his scene a bit...

#include "colors.inc"

camera {
   location <0,2.5,-7>
   right    x*image_width/image_height
   look_at  <0,2,0>
}

light_source {
   <-20, 30, 0>
   White
}
light_source {
   <0,2.5,-8>
   White
}

sky_sphere {
   pigment {
      gradient y
      color_map {
         [0 Black]
         [0.5 Gray75]
         [1 Black]
      }
   }
}

#declare X = function(T) { sin(T) };
#declare Y = function(T) { cos(T) };
#declare Z = function(T) { T };

#declare CylRadius = 0.1;
#declare MinT = 0;
#declare MaxT = 2*pi;
#declare Steps = 100;

union {

   #declare Ind = 0;
   #while(Ind < Steps)
      #declare T1 = MinT + (MaxT-MinT)*Ind/Steps;
      #declare T2 = MinT + (MaxT-MinT)*(Ind+1)/Steps;
      #declare P1 = <X(T1), Y(T1), Z(T1)>;
      #declare P2 = <X(T2), Y(T2), Z(T2)>;
      sphere { P1, CylRadius }
      cylinder { P1, P2, CylRadius }
      #declare Ind = Ind+1;
   #end

   texture {
      pigment {Orange}
      normal {bumps scale 0.02}
      finish {
         specular 0.3
         roughness 0.005
      }
   }

   rotate <-90,0,0>
   translate <0,-1,2.5>
}

plane { y, -1
   pigment {
      cells
      color_map {
         [0 Blue]
         [1 ForestGreen]
      }
   }
}


Post a reply to this message

From: Warp
Subject: Re: povray and 3D graphs
Date: 17 Apr 2008 06:52:56
Message: <48072c08@news.povray.org>
Daniel C. Bastos <dba### [at] yahoocombr> wrote:
> What I would like to do on your code is to keep the plane where it is
> --- that would be my xy-plane --- and make the helix start from the
> plane and spiral up, because that's how this helix should be as x varies
> according to cos(t) and y to sin(t) and z = t. That is, while x and y
> circle around, z keeps on going up (or down.)

  Either swap the contents of the y and z components of the vectors, like
this:

    #declare P1 = <X(T1), Z(T1), Y(T1)>;
    #declare P2 = <X(T2), Z(T2), Y(T2)>;

or alternatively add a "rotate -x*90" at the very end of the 'union' block.

-- 
                                                          - Warp


Post a reply to this message

From: Karl Anders
Subject: Re: povray and 3D graphs
Date: 17 Apr 2008 11:20:03
Message: <web.480769fdc9f0a145ebd2120f0@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
>
>   Either swap the contents of the y and z components of the vectors,
> <snip>
> or alternatively add a "rotate -x*90" at the very end of the 'union' block.
>

Oops, an unexpected glitch from the master :-)
The last one won't exchange z and y, not generally. Since I'm a
righthanded-z_is_up-guy too, I usually use the matrix stuff to exchange y and z
for models made by other people:

#include "transforms.inc"
#declare Swap_yz_trans = transform{ Shear_Trans(x, z, y) };

#declare RightHandedObject = object{
   LeftHandedObject transform Swap_yz_trans };

hope that helps

Greetings
Karl


Post a reply to this message

From: Alain
Subject: Re: povray and 3D graphs
Date: 18 Apr 2008 11:42:34
Message: <4808c16a@news.povray.org>
> //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
> }
> 
What kind of adaptive area_light is that? Adaptive 2 tries to start with a 5 by 
5 array, but your's is only 4 by 4... So the adaptive does nothing.
adaptive 0 start with a 2 by 2 array.
adaptive 1 with a 3 by 3
adaptive 2 with 5 by 5
adaptive 3 with 9 by 9
adaptive 4 with 17 by 17

The optimum array dimentions are: 5, 9, 17, 33, 65, 129, 257,...

-- 
Alain
-------------------------------------------------
OFFICE ARITHMETIC
Smart boss + smart employee = profit
Smart boss + dumb employee = production
Dumb boss + smart employee = promotion
Dumb boss + dumb employee = overtime


Post a reply to this message

From: Sherry Shaw
Subject: Re: povray and 3D graphs
Date: 18 Apr 2008 11:56:31
Message: <4808c4af@news.povray.org>
Daniel C. Bastos wrote:

There are some very good tutorials here:

http://www.f-lohmueller.de/pov_tut/pov__eng.htm

Tutorials number VI, IX through XIV, and XXI look like they might be 
especially relevant.

Hope this helps,

--Sherry Shaw


-- 
#macro T(E,N)sphere{x,.4rotate z*E*60translate y*N pigment{wrinkles scale
.3}finish{ambient 1}}#end#local I=0;#while(I<5)T(I,1)T(1-I,-1)#local I=I+
1;#end camera{location-5*z}plane{z,37 pigment{granite color_map{[.7rgb 0]
[1rgb 1]}}finish{ambient 2}}//                                   TenMoons


Post a reply to this message

From: Daniel C  Bastos
Subject: Re: povray and 3D graphs
Date: 20 Apr 2008 00:00:18
Message: <slrng0lft6.oa2.dbast0s@yahoo.com.br>
In article <48071e5a@news.povray.org>,
Tim Attwood wrote:

>> What I would like to do on your code is to keep the plane where it is
>> --- that would be my xy-plane --- and make the helix start from the
>> plane and spiral up, because that's how this helix should be as x varies
>> according to cos(t) and y to sin(t) and z = t. That is, while x and y
>> circle around, z keeps on going up (or down.)
>
> You can rotate unions like any other object, there's a good tutorial in
> the manual too.

That's true. I have already read that, when they talk about that green
cube. This seems better to write than swaping coordinates which might
seem a bit misleading.

>> So what I think it's happening here is that while I keep on thinking on
>> the xyz-axis as I do, the povray puts the z axis as going from outside
>> my screen into it. So if I swap y and z I should get what I'd like, and
>> apparently I do.
>
> POV uses a left handed coordinate system, like if you point with
> your left hand, thumb up is y, pointer finger in is z, and middle
> finger right is x. Rotations are the same way, if you trace from your
> left palm looping around your fingers that is the direction of rotation
> used for each axis.

Got it.

>> I also took your code and plotted it from -25pi to 25pi and it spirals
>> just right. Cool. I'm impressed. This is what I'm looking for. Thanks
>> for the introduction.
>
> Yeah, Warp knows his stuff =)
> I fiddled with his scene a bit...

Looks good. I took 

                    #declare Z = function(T) { T };

and made it 

                   #declare Z = function(T) { T/3 };

so that we can see it looking more like a spring. Looks pretty
good. This is the kind of function graph I'd like to have. :-) Cool
stuff.

>
> #include "colors.inc"
>
> camera {
>    location <0,2.5,-7>
>    right    x*image_width/image_height
>    look_at  <0,2,0>
> }
>
> light_source {
>    <-20, 30, 0>
>    White
> }
> light_source {
>    <0,2.5,-8>
>    White
> }
>
> sky_sphere {
>    pigment {
>       gradient y
>       color_map {
>          [0 Black]
>          [0.5 Gray75]
>          [1 Black]
>       }
>    }
> }
>
> #declare X = function(T) { sin(T) };
> #declare Y = function(T) { cos(T) };
> #declare Z = function(T) { T };
>
> #declare CylRadius = 0.1;
> #declare MinT = 0;
> #declare MaxT = 2*pi;
> #declare Steps = 100;
>
> union {
>
>    #declare Ind = 0;
>    #while(Ind < Steps)
>       #declare T1 = MinT + (MaxT-MinT)*Ind/Steps;
>       #declare T2 = MinT + (MaxT-MinT)*(Ind+1)/Steps;
>       #declare P1 = <X(T1), Y(T1), Z(T1)>;
>       #declare P2 = <X(T2), Y(T2), Z(T2)>;
>       sphere { P1, CylRadius }
>       cylinder { P1, P2, CylRadius }
>       #declare Ind = Ind+1;
>    #end
>
>    texture {
>       pigment {Orange}
>       normal {bumps scale 0.02}
>       finish {
>          specular 0.3
>          roughness 0.005
>       }
>    }
>
>    rotate <-90,0,0>
>    translate <0,-1,2.5>
> }
>
> plane { y, -1
>    pigment {
>       cells
>       color_map {
>          [0 Blue]
>          [1 ForestGreen]
>       }
>    }
> }
>
>


Post a reply to this message

Goto Latest 10 Messages Next 7 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.