We are about to switch to a new forum software. Until then we have removed the registration on this forum.
http://piratepad.net/2qUISlwOK7 line 26
or
//variables for matrix to record frequency distribution of relative position in group over the field
public int resolution = 10;
public int cols = 1450 / resolution;
public int rows = 950 / resolution;
public double [][] matrixWorld = new double [cols][rows];
//blah blah blah in between
PVector[] normalGroupVector = new PVector [boids.size()];
for (int b = 0; b < normalGroupVector.length; b++) {
normalGroupVector[b] = new PVector(0, 0);
for (int i = 0; i < groupPerBoid.length; i++) {
for (int j = 0; j < groupPerBoid[0].size(); j++) {
Agent boid = (Agent) groupPerBoid[i].get(j);
normalGroupVector[b].add(boid.vel);
normalGroupVector[b].div(groupPerBoid[i].size());
normalGroupVector[b].normalize();
}
}
}
for (int i = 0; i < matrixWorld.length; i++) {
for (int j = 0; j < matrixWorld[0].length; j++) {
for (int n = 0; n < normalGroupVector.length; n++) {
Agent boid = (Agent) boids.get(n);
if (dist(normalGroupVector[n].x, normalGroupVector[n].y, boid.vel.x, boid.vel.x) >= (normalGroupVector[n].mult(0.75)) && boid.type == 2) {
matrixWorld[boid.getX()][boid.getY()]++;
}
}
}
}
I've tried PVector.mult(0.75) which throws "The operator >= is not applicable to the argument type(s) PVector, float." I think that's because PVector.mult(float) modifies the PVector but doesn't return a value.
So then I tried = (mult(PVector, float) which throws a "The function mult(PVector, float) does not exist", even tho it's in the autogenerated reference doc - http://processing.org/reference/javadoc/everything/processing/core/PVector.html#mult(processing.core.PVector, float)
I guess maybe I could overcome the problem of PVector.mult(float) not returning a value by constructing in an intermediate variable to hold the multiplicands before testing if the group normalized vector minus the individual normalized vector is greater than or equal to 3/4 of the group normalized vector, i.e. is the individual in the front quartile of it's current group, would that work? I'll try it now...
(The reason I'm using a double[][] to record frequencies is because that's what the JHeatChart package accepts. http://www.tc33.org/jheatchart/javadoc/)
I'm a biology student recently fallen (alright I jumped) into the deep end of coding, so I may have misunderstood or missed something fundamental. I'm not a CS student. 'This isn't homework,' it's the last stage of my dissertation project analysis, and I'm very very close to the deadline!
Thank you!!
Answers
There are 3 overloaded forms for method mult():
http://processing.org/reference/PVector_mult_.html
Version w/ 1 argument, as you're currently doing, acts upon the object itself, but returns
void
.The other 2 calculate, but don't modify the 1st PVector instance, and return a PVector w/ the result.
Thanks!
I tried both
if (dist(normalGroupVector[n].x, normalGroupVector[n].y, boid.vel.x, boid.vel.x) >= mult(normalGroupVector[n], 0.75, quartileGroupVector) && boid.type == 2) { }
and
mult(normalGroupVector[n], 0.75, quartileGroupVector);
and both throw "The function mult(PVector, float, PVector) does not exist"
Why?
Apologies for the multiple posting. The page was saying "Error: could not pass to xml. Please try again" so I did, didn't realise it was actually posting...
Indeed, there's no such function in Processing! What you want is the PVector's method mult()! :-B
In its reference link I've posted, we can read:
Its 2nd example illustrates that point above! 8-X
In short, a static method uses the very class name instead of an object reference:
PVector.mult(normalGroupVector[n], 0.75, quartileGroupVector);
In your example above, after prefixing mult() w/ PVector, fields x, y, z from normalGroupVector[n] are multiplied by
.75
.Then the result in saved in quartileGroupVector's fields x, y, z. However, normalGroupVector[n]'s fields are unaffected. :P