Break ArrayList into chunks.
in
Programming Questions
•
2 months ago
Hi all:
I have an ArrayList with Vec3D's in it. I want to break it off into chunks of 16 items each, and then connect the points to build a curve.
CurveData.TXT is a text file with points separated by commas. in x,y,z format 272 lines total. I want to use the first 16 points to draw a curve, the next chunk of 16 points to draw the next curve, and so on. I'm reading the txt file and putting the data into an arraylist of Vec3D in the setup:
- void readCurveData() {
- myPoints = new ArrayList();
- String[] curveData = loadStrings("data/curveData.txt");
- println(curveData.length);
- for (int i=0; i<curveData.length;i++) {
- String[] textLine = split(curveData[i], ',');
- float [] coord;
- coord = new float[3];
- coord[0] =(float) (float(textLine[0]));
- coord[1] =(float)(float(textLine[1]));
- coord[2] =(float)(float(textLine[2]));
- // println(coord[0] + "," + coord[1] + "," + coord[2]);
- Vec3D a = new Vec3D(coord[0], coord[1], coord[2]);
- myPoints.add(a);
- }
- void drawCurveData() {
- int numberOfCurves=int(myPoints.size()/16);
- int numberOfPointsIncurve = 16;
- /*
- for (int i=0; i<myPoints.size();i++) {
- Vec3D a = (Vec3D) myPoints.get(i);
- stroke(50, 125, 125);
- strokeWeight(3);
- point(a.x,a.y,a.z);
- }*/
- for (int i = 1; i<numberOfCurves;i++) {
- Spline3D[] = new Spline3D[numberOfCurves];
- for (int j=1; j<numberOfCurves;j++) {
- Vec3D vert = (Vec3D) myPoints.get((i*j)-1);
- Spline3D[i].add(vert);
- }
- }
- }
Any other approach is welcome. Again, the objective is to break the ist into chunks, in order to draw the curves independently.
Many thanks.
1