Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Import location and velocity data from txt

$
0
0

Hello, I have a txt file that contains the location and velocity data for particles and I am trying to import it in processing but I have problem with the syntax. Here is an example of my txt file:

0.671470046043 0.0592122897506 -0.597842812538 0.165664941072 2.11239433289 0.165294915438,0.734478414059 0.0503597855568 -0.534131884575 0.207550317049 1.82068312168 -0.327298223972,0.784207165241 0.0618093051016 -0.443658143282 0.095640823245 2.19577264786 -0.197497576475

which is actually loc1.x loc1.y loc1.z vel1.x vel1.y vel1.z, loc2.x loc2.y loc2.z vel2.x vel2.y vel2.z, .....

here is the code that I am trying to write

  void importPts() {
    String[] pointsA = loadStrings(loadPts);
    importParticles = new Particle[pointsA.length];
    for (int i = 0; i < pointsA.length; i++) {
      String a = pointsA[i];
      String[] a1 = split(a, ',');
      float x1 = float(a1[0]);
      float y1 = float(a1[1]);
      float z1 = float(a1[2]);
      float v1 = float(a1[3]);
      float v2 = float(a1[4]);
      float v3 = float(a1[5]);
      Vec3D loc1 = new Vec3D(x1, y1, z1);
      Vec3D vel1 = new Vec3D(v1,v2,v3);
      Particle pt = new Particle(loc1,vel1);
      importParticles[i]=pt;
    }
  }

for some reason I don't seem to be getting any results. Any idea of what I'm doing wrong?

thank you for the help!


Viewing all articles
Browse latest Browse all 2896

Trending Articles