POV-Ray : Newsgroups : povray.animations : How to animate ??????????????? : Re: How to animate ??????????????? Server Time
28 Sep 2024 17:56:43 EDT (-0400)
  Re: How to animate ???????????????  
From: Dave VanHorn
Date: 21 Feb 2008 15:45:00
Message: <web.47bde1ca86d65c51a08ed15e0@news.povray.org>
Ok, just so it's out here and useful for someone else, here's my routine that
inputs triplets of data points from an accelerometer, finds the peak, and
renders 500 samples either side of the peak.

We did a small linux thing to fix the CSV output, but it would be nice if pov
could read CSV files output by excel in the future, in the form of :
Data1, Data2, Data3
Data1, Data2, Data3

Thanks tons for the help!


//Initialize with safe values
#declare Lines_In_File = 0;
#declare MaxX=0;
#declare MaxY=0;
#declare MaxZ=0;
#declare Zabs=0;
#declare YPeak=-10000;
#declare PeakLine=0;

//Find how many lines in the file
#fopen MyFile "drop3.csv" read

#while (defined(MyFile))
  #read (MyFile,Xval,Zval,Yval)   // Z is up/down

  // Find max Z val
  #declare Zabs=abs(Zval);
  #if (Zval>Zabs)
   #declare Zabs=Zval;
  #end

  // Find max Y val
  #if (Yval>YPeak)
   #debug concat("New Peak= ", str(Yval,1,6), " Old= ",str(YPeak,1,6)," in line
",str(Lines_In_File,1,0), "\n")
   #declare YPeak=Yval;
   #declare PeakLine=Lines_In_File; //off by one, but I don't care
  #end

  // Find max X val
  #declare Xabs=abs(Xval);
  #if (Xval>Xabs)
   Xabs=Xval
  #end

  // Count a line
  #declare Lines_In_File=Lines_In_File+1 ;
#end

  #debug concat("Just Counted ", str(Lines_In_File,1,0), " lines in the file",
"\n")
  #debug concat("REMEMBER TO SET THE -KFF parm to ", str(Lines_In_File,1,0),
"\n")
  #debug concat("Peaks X=", str(Xabs,4,9)," Y=",str(YPeak,4,9),"
Z=",str(Zabs,4,9), "\n")
  #debug concat("REMEMBER to check this against the scene view! ","\n")
  #debug concat("Peak impact in line  ", str(PeakLine,1,0), "\n")
#fclose MyFile


// Having Lines_In_File now holding the lines count

#if (PeakLine < 501)
#declare Start = PeakLine;
#else
#declare Start     = PeakLine-500; //500 = 0.1 sec before impact peak
#end

#if (Start+1000 < Lines_In_File)
 #declare End       = Start+1000; //Lines_In_File;
#else
   #declare End = Lines_In_File
#end

#declare My_Clock  = Start+(End-Start)*clock;
#declare Count     = 0;
#declare Read_Line = int(My_Clock);

#debug concat("Start     = ", str(Start,5,2),"\n")
#debug concat("End       = ", str(End,5,2),"\n")
#debug concat("REMEMBER TO SET THE -KFF parm to ", str((End - Start),1,0), "\n")
#debug concat("My_Clock  = ", str(My_Clock,5,2),"\n")
#debug concat("Read_Line = ", str(Read_Line,5,2),"\n")

#fopen MyFile "drop3.csv" read
 #while (Count<Read_Line)
  #read (MyFile,Xval,Zval,Yval) // In POV, X and Z are horizontal, Y is vertical
  #declare Count=Count+1;
 #end
#fclose MyFile

//debugging output
#debug concat("Just Read line ", str(Count,1,0), "\n")
#declare  EX=str(Xval,12,9);
#declare  WY=str(Yval,12,9);
#declare Zee=str(Zval,12,9);
#debug concat(EX," ",WY," ",Zee,"\n")


// Flip polarity on Yval
#declare Yval = (0 - Yval);

//Trap zero case which would make degenerate cylinder
#if (Xval+Yval+Zval=0)
 Xval=0.001
 Yval=0.001
 Zval-0.001
#end

//Scaling
#declare ScaleVal = 1;
#declare Xval=Xval/ScaleVal;
#declare Yval=Yval/ScaleVal;
#declare Zval=Zval/ScaleVal;

From here, I build the scene, using Xval, Yval, and Zval to stretch an arrow in
the appropriate direction.


Post a reply to this message

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