Planes of Points in 3D Space
in
Contributed Library Questions
•
1 years ago
Hi All,
Still new to processing, so am turning to the community for some troubleshooting. I'm working on developing a script that creates regions of points in 3D through some vector math. These points will ultimately be moving agents that define strands, but I am first trying to setup and test these regions by drawing points. I'm running into trouble with my ArrayLists and am getting the error "the field ArrayList is not visible." Script and image of how I am generating these points on respective 3D planes is below.
Thanks for the help.
Code:
import toxi.geom.*;
import peasy.*;
PeasyCam cam;
float envSize = 300;
float degree = 1.57;
ArrayList agentPopulation;
ArrayList strandPopulation;
void setup () {
size(800, 800, P3D);
smooth();
cam = new PeasyCam (this, 800);
for (int i=0; i<5; i++) {
//create first vector that defines area
Vec3D A = new Vec3D(random(-envSize, envSize), random(-envSize, envSize), random (-envSize, envSize));
//create rotation axis for first vector
Vec3D Rot = new Vec3D(random(-envSize, envSize), random(-envSize, envSize), random (-envSize, envSize));
//create copy of first vector to be rotated
Vec3D AC = new Vec3D(A.copy());
//rotate copied vector to new position
AC.getRotatedAroundAxis(Rot, degree);
//define max values for vectors
float vLength01 = random(40, 80);
float vLength02 = random(40, 80);
//restrict magnitude of Vector A and Vector AC
A.getNormalizedTo(vLength01);
AC.getNormalizedTo(vLength02);
//define arraylists
ArrayList strandPopulation = new ArrayList();
//create for loop to create agents in given region
for (int j=0; j<10; j++) {
ArrayList agentPopulation = new ArrayList();
for (int k=0; k<15; k++) {
float scalar = random(0, 1);
A.scaleSelf(scalar);
AC.scaleSelf(scalar);
A.addSelf(AC);
agentPos a = new agentPos(A, i);
agentPopulation.add(a);
}
strandPopulation.add(new strand(agentPopulation));
}
}
}
void draw () {
background(0);
//render the points of the strands
for (int i=0; i<strandPopulation.size; i++) {
strand s = (strand) strandPopulation.get(i);
s.render();
}
}
class agent {
// states
Vec3D pos;
strand myStrand;
int myIndex;
// constructor
agent(Vec3D p, strand s, int i) {
pos = p.copy();
myStrand = s;
myIndex = i;
}
}
class agentPos {
//states
Vec3D loc; //vector "location"
int region;
//constructor
agentPos(Vec3D l, int r) {
loc = l.copy();
region = r;
}
}
class strand {
// states
ArrayList strandAgents;
// constructor
strand(ArrayList pts) { // pts is an arraylist of Vec3D
strandAgents = new ArrayList();
for (int i = 0; i < agentPopulation.size(); i++) {
agentPos a = (agentPos) agentPopulation.get(i);
Vec3D pt = (Vec3D) a.loc;
strandAgents.add(new agent(pt, this, i)); // pos, myStrand, myIndex
}
}
void render() {
noFill();
stroke(255);
for (int i = 0; i < strandAgents.size(); i++) {
agent a = (agent) strandAgents.get(i);
point(a.pos.x, a.pos.y, a.pos.z);
}
}
}
1