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

ArrayList of PVectors Setup and Display

$
0
0

Hi, I was wondering if anyone here can help me getting my head around PVectors. I am creating a visualization of points on Earth. For this I am creating an arrayList of PVectors, which get their data from a csv (Longitude, Latitute). My problem is the csv has over 88 000 lines and slows down the program when drawn in void draw() Therefore I wanted to initialize the PVectors in void createLocationPoints()) and only display them in draw with another funciton... For instance with giving the points a stroke weight. Can someone explain how I can display the function LocationVectors.add(new PVector(x, y, z)); in this example? I was thinking of something similar like Daniel Schiffmans simple particle example from the documentation but I can't quite get my head around it. Please be gentle, I am quite new to processing. Thanks a lot!

import peasy.*;

PeasyCam cam;

//Radius Earth
float radius = 6371000/50000; //global scale

//Tables
Table dataTable;
Table locationTable;

//Data lists
FloatList AffordabilityIndex;
FloatList LongituteAI;
FloatList LatituteAI;
FloatList AltituteAI;

//Locations Lists
FloatList settlementPoint;
FloatList Longitute;
FloatList Latitute;
FloatList Altitute;

float x;
float y;
float z;

PVector LocationVector;
//PShape points;

ArrayList<PVector> LocationVectors;

void setup() {
  size(800, 800, P3D);
  smooth();
  dataTable = loadTable("dataTable.csv", "header");
  locationTable = loadTable("locationTable.csv", "header");

  LocationVectors = new ArrayList<PVector>();

  cam = new PeasyCam(this, 4000);
  cam.setMinimumDistance(250); //0
  cam.setMaximumDistance(500); //8000

  ////LOCATIONS
  ////create location lists
  Longitute = new FloatList();
  Latitute = new FloatList();
  Altitute = new FloatList();
  //Read and store CSV
  for (int i = 0; i < locationTable.getRowCount(); i++) {
      TableRow rowLocationTable = locationTable.getRow(i);
      Longitute.append(rowLocationTable.getFloat("Longitute"));
      Latitute.append(rowLocationTable.getFloat("Latitute"));
      Altitute.append(rowLocationTable.getFloat("Altitute"));
    }


  //DATA
  //create data lists
  AffordabilityIndex = new FloatList();
  LongituteAI = new FloatList();
  LatituteAI = new FloatList();
  //Read and store CSV
  for (int i = 0; i < dataTable.getRowCount(); i++) {
    TableRow rowDataTable = dataTable.getRow(i);
    AffordabilityIndex.append(rowDataTable.getFloat("Affordability Index")*1);
    LongituteAI.append(rowDataTable.getFloat("Longitute"));
    LatituteAI.append(rowDataTable.getFloat("Latitute"));
    //println(Longitute, Latitute, AffordabilityIndex);
  }

  createLocationPoints();

}

void draw() {

  background(255);
  shape(points);
  displayLocationPoints();

  //DRAW DATA

  AltituteAI = AffordabilityIndex;

  strokeWeight(4);
  stroke(0);
  beginShape(POINTS);

  for (int i = 0; i < LongituteAI.size(); i++) {
    //Convert to Cartesian Coordinates
    //float a = pow( 1, 3);  // Sets 'a' to 1*1*1 = 1
    float f = 0; // flatening
    float lambda = atan(pow((1 - f), 2) * tan(radians(LatituteAI.get(i))));    // lambda

    float y = radius * cos(lambda) * cos(radians(LongituteAI.get(i))) + AltituteAI.get(i) * cos(radians(LatituteAI.get(i))) * cos(radians(LongituteAI.get(i))); //swaped x&y
    float x = radius * cos(lambda) * sin(radians(LongituteAI.get(i))) + AltituteAI.get(i) * cos(radians(LatituteAI.get(i))) * sin(radians(LongituteAI.get(i)));
    float z = radius * sin(lambda) + AltituteAI.get(i) * sin(radians(LatituteAI.get(i)));

    vertex(x, y, z);
  }
  endShape();

  noStroke();
  sphere(radius*0.98);

}

void createLocationPoints(){
    //DRAW ALL LOCATIONS
  //strokeWeight(1);
  //stroke(0);
  //beginShape(POINTS);
   //points = createShape();
   //points.beginShape();

  for (int i = 0; i < Longitute.size(); i++) {
    //Convert to Cartesian Coordinates
    //float a = pow( 1, 3);  // Sets 'a' to 1*1*1 = 1
    float f = 0; // flatening
    float lambda = atan(pow((1 - f), 2) * tan(radians(Latitute.get(i))));    // lambda

    float y = radius * cos(lambda) * cos(radians(Longitute.get(i))) + Altitute.get(i) * cos(radians(Latitute.get(i))) * cos(radians(Longitute.get(i))); //swaped x&y
    float x = radius * cos(lambda) * sin(radians(Longitute.get(i))) + Altitute.get(i) * cos(radians(Latitute.get(i))) * sin(radians(Longitute.get(i)));
    float z = radius * sin(lambda) + Altitute.get(i) * sin(radians(Latitute.get(i)));

    vertex(x, y, z);

    LocationVector = new PVector(x, y, z);
    LocationVectors.add(new PVector(x, y, z));

  }

  //endShape();
  //points.endShape();
  println(LocationVectors);
}

void displayLocationPoints(){
  strokeWeight(10);
  stroke(0);

}

Viewing all articles
Browse latest Browse all 2896

Trending Articles