Parsing points from a text file

PVector[] globe;
float x = 0;
float y = 0;
float z = 0;
import peasy.*;

PeasyCam cam;

void setup() {
size(600, 600, P3D);
cam = new PeasyCam(this, 500);
globe = new PVector[30];
stroke(255);
lights();
}
void draw(){
String[] lines = loadStrings(“Points.txt”);
String All_Points = join(lines, " ");
String[] P = splitTokens(All_Points, ", ");
println(All_Points);
for (int i=0 ; i<30 ; i = i+3) {
x = float(P[i]);
println(x);
}
for (int j=1 ; j<30 ; j = j+3) {
y = float(P[j]);
println(y);
}
for (int k=2 ; k<30 ; k = k+3) {
z = float(P[k]);
println(z);
}
for (int i=0 ; i<10 ; i++){
globe[i] = new PVector(x,y,z);
}
for (int i=0 ; i<10 ; i++){
PVector v1 = globe[i];
stroke(255);
strokeWeight(4);
point(v1.x, v1.y, v1.z);
scale(5.0);
}
}

I am new to code, so I’m not sure what is going wrong. I have a text file which contains a series of points in different lines. I need to convert every group of three points into PVectors so that I can draw them as points in the canvas. The points are in rectangular coordinates, so it would be nice to be able to convert them once and then draw the (x,y,z) representation of the points.

The text file is organized as:
1, 1.5708, 0,
1.4142, 0.7854, 0,
1, -1.5708, 0,
1.4142, 0.7854, 0,
1, 1.5708, 1,
1.4142, 0.7854, 1,
1, -1.5708, 1,
1.4142, 0.7854, 1,
1, -1.5708, 2,
1, 1.5708, 2

Hello @Aaron_Barber272 ,

Please format your code as a courtesy to the community:
https://discourse.processing.org/faq#format-your-code

Each of your loops ends with x, y, and z set to the last execution of that loop and each element of globe[] is the same.

You can do most of this in setup() and use the final array(s) you need in draw().

Try this in one loop which acts on each element:

String lines [] = loadStrings("Points.txt");

float[] pv;
PVector[] globe = new PVector[10];

int i = 0;
pv = float(splitTokens(lines[i], ","));
globe[i] = new PVector(pv[0], pv[1], pv[2]);
print(globe[i].x, globe[i].y, globe[i].z);

In a loop (you can add one) it outputs:

image

10 points plotted (2 are duplicates):

I used this instead of scale():

:)