POV-Ray : Newsgroups : povray.general : Read data and draw sphere? : Re: Read data and draw sphere? Server Time
1 Aug 2024 10:12:06 EDT (-0400)
  Re: Read data and draw sphere?  
From: kurtz le pirate
Date: 26 Nov 2005 09:22:46
Message: <kurtzlepirate-0BCF99.15224526112005@news.povray.org>
In article <web.43886ab1919621bdcce6fd2b0@news.povray.org>,
 "cutejuly" <cut### [at] hotmaicom> wrote:

::Hi!
::
::I looked at some answers to read data and to draw spheres in 3D BOX. I am
::very interested in that. So, I am trying to do those. But, drawn spheres is
::not matched with data as a position. My data file is 'practice.txt'. Also,
::format is as following:
::
::100.2 200.3 0
::200.1 100.2 0
::10.2 23.1 0
::etc
::
::For original data(sphere position), I use 'space' instead of 'comma' between
::values.
::
::Program is also as following:
::
::#fopen MyFile "practice.txt" read
::  #while (defined(MyFile))
::    #read (MyFile,Var1,Var2,Var3)
::
::    sphere {
::    <Var1, Var3, Var2>, 0.5
::    texture {
::      pigment { color Yellow }
::      }
::    }
::#end
::
::
::Is there any problem on the program and/or data file format?
::
::Thank you very much for your help.

at http://www.povray.org/documentation/view/3.6.1/238/ you can read :
"The format of the data to be read must be a series of valid string 
literals, float literals, or vector literals SEPARATED BY COMMA."

any valid reason to use a space instead of comma ?

can can play with this small sample code (not tested in deep)
// --------------------------------------------------------------
#version unofficial MegaPov 1.21;

#declare alea=seed(13589);
#declare theFileName="outfile.txt";
#declare floatNum = 30;

// --- fill the file with random floats numbers
#debug "fill the file"
#declare index=1;
#fopen myFileRef theFileName write
#while (index<floatNum)
  #write (myFileRef, 10000*rand(alea)-5000,",")
  #set index=index+1;
#end
#write (myFileRef, 10000*rand(alea)-5000)
#fclose myFileRef
#debug "\n\n"

// --- now, read numbers as single float value
#debug "Read as single value"
#declare index=1;
#fopen myFileRef theFileName read
#while (defined(myFileRef))
  #read (myFileRef,oneFloat)
  #debug concat(str(index,3,0)," : ",str(oneFloat,10,3),"\n")
  #set index=index+1;
#end
#fclose myFileRef
#debug "\n\n"

// --- say that this is vectors...
#debug "Read as vector value...\n"
#declare index=1;
#fopen myFileRef theFileName read
#while (defined(myFileRef))
  #read (myFileRef,xFloat, yFloat, zFloat)
  #debug concat(str(index,3,0)," : 
<",str(xFloat,10,3),",",str(yFloat,10,3),",",str(zFloat,10,3),">\n")
  #set index=index+1;
#end
#fclose myFileRef
#debug "\n\n"

klp ;)


Post a reply to this message

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