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