We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › point data form txt file
Page Index Toggle Pages: 1
point data form txt file (Read 503 times)
point data form txt file
Nov 6th, 2007, 12:46pm
 
hei there!

i'm trying to import particle data from a textfile.

looks like:

-0.372068,0.905460,0.388421
-0.368527,0.905460,0.380401
-0.398187,0.905460,0.379182
-0.320218,0.905460,0.364631
...
...
...

i want to place a point at all coordinates given! this is, what i'm doing now:

for (int i = 0; i< points.length; i++){
   Point[i] = new Point(int(random(-10, 10)), int(random(-10, 10)),
   int(random(-10, 10)), int(random(-140, 140)), int(random(-140, 140)),
   int(random(-140, 140)));

how can i integrate the txt.file? and check how many points there are?

thx for your help! mias



Re: point data form txt file
Reply #1 - Nov 6th, 2007, 1:40pm
 
I'm making some assumptions about your point class here, I notice you've got 6 values, but I'm only providing 3 here, the x/y/z coords, you'll have to mess with thsi to fit it to your Point class.

Code:
String[] lines=loadStrings("myfile.txt");
Point[] points=new Point[lines.length];
for(int i=0;i<lines.length;i++)
{
String[] coords=split(lines[i],",");
Point[i]=new Point(float(coords[0]),float(coords[1]),float(coords[2]));
}
Re: point data form txt file
Reply #2 - Nov 6th, 2007, 2:53pm
 
thx for the help! - works great (all the assumptions you made totaly fitted) =)
Page Index Toggle Pages: 1