|
|
stevenvh wrote:
> In my code I want to generate a series of prisms dynamically, where both the
> number of points and their coordinates are read from a file. I have no idea how
> to do this, so any hints be greatly appreciated.
> Regards,
> Steven
You could have an include file which contains an array:
#declare pn = pi*2/6;
#declare points=
array[7]{
<sin(pn*0),cos(pn*0)>,
<sin(pn*1),cos(pn*1)>,
<sin(pn*2),cos(pn*2)>,
<sin(pn*3),cos(pn*3)>,
<sin(pn*4),cos(pn*4)>,
<sin(pn*5),cos(pn*5)>,
<sin(pn*0),cos(pn*0)>
}
Then you can #include the file into your scene and write something like
this:
prism{
-.5,.5,dimension_size(points,1)
#declare V=0;
#while(V<dimension_size(points,1))
points[V]
#declare V=V+1;
#end
pigment{rgb 1}
}
You'll probably want to generate the include file automatically. You
should check into #fopen, #write and #fclose (3.2.2.3 File I/O
Directives). You shouldn't have to #read a file to accomplish your goal.
I hope this helps.
Sam
Post a reply to this message
|
|
|
|
"stevenvh" <nomail@nomail> wrote in message
news:web.49893e4a14f123fac0721a1d0@news.povray.org...
> In my code I want to generate a series of prisms dynamically, where both
> the
> number of points and their coordinates are read from a file. I have no
> idea how
> to do this, so any hints be greatly appreciated.
> Regards,
> Steven
Or, if you want to #read straight from an existing data file that is in csv
format you can do that too. The only tricky bit with mixed data types (point
counts and coordinates) is making sure you don't get out of step when trying
to read the file. The end of the file needs to be quite tidy too (e.g. no
trailing comma on the last line), otherwise the end-of-file may not be
detected when it needs to be detected.
If you have a csv file containing:
7,
<-1 ,0>,
<-0.5,0>,
< 0 ,1>,
<-0.5,2>,
<-1 ,2>,
<-1.5,1>,
<-1 ,0>,
7,
< 1 ,0>,
< 0.5,0>,
< 0 ,1>,
< 0.5,2>,
< 1 ,2>,
< 1.5,1>,
< 1 ,0>
You can read this in and use it to draw prisms as follows:
camera {location <0,3,-2> look_at <0,1,1>}
light_source {<-10,20,50>, rgb 1}
// Randomisation seed is just for the color
#declare S = seed(3);
#fopen MyFile "datafile.csv" read
#while (defined(MyFile))
#read(MyFile,PointCount)
prism{
0,1,PointCount
#declare I=0;
#while(I<PointCount)
#undef ThisPoint
#read(MyFile,ThisPoint)
// Add this point into the prism:
ThisPoint
#declare I=I+1;
#end
pigment{rgb <rand(S),rand(S),rand(S)>}
}
#end
This uses two nested #while loops. The first reads the file till there's no
more values to read. Inside the first loop we read a value which needs to be
a whole number of points, then the second #while loop reads each point (uv
vector) in turn and uses it in the prism definition. When the first prism is
finished the outer loop looks for the next point count, and so on, until the
end of the file. You can add as many sets of points to the file as you need.
Regards,
Chris B.
Post a reply to this message
|
|