Closed NickyDundas closed 8 years ago
This appears to be an issue with Java pointers. As a workaround (until I think of a more general solution) you can build up body unions at most one level at a time. In the example below, I make a two-foil system, and then add one more to make a three foil system. If I move either of the foils in two
they will also update in three
automatically.
BodyUnion two,three;
void setup() {
int n=(int)pow(2, 6)+2; // number of grid points
size(800, 800); //sim window size
Window view = new Window(n, n);
float xFoila = 20, xFoilb = 20, xFoilc = 20;
float yFoila = 15, yFoilb = 25, yFoilc = 35;
float resolution = 16, thickness = 0.2;
two = new BodyUnion(new NACA(xFoilb, yFoilb, resolution, thickness, view),
new NACA(xFoilc, yFoilc, resolution, thickness, view));
three = new BodyUnion(new NACA(xFoila, yFoila, resolution, thickness, view), two);
}
void draw() {
background(0);
two.b.translate(0, 0.1);
two.b.rotate(0.01);
three.update();
three.display();
}
The new version of BodyUnion lets you add as many bodies on as you want. To change their dynamics you could use
for (Body body : group.bodyList){body.follow(kinematics);}
where kinematics
is a function that returns a PVector with (x,y,phi) as in the new foil example in the LilyPad.pde file.
When trying to have three NACA bodies moving independently, errors arise. Three bodies are created using the bodyUnion function. The bodies move correctly with two bodies, but not for three.
For movement with three bodies, it will still move the first body (body.a) however will not recognise the other two bodies as either body.b / body.c or body.b.a
Here is some sample coding of the issue: BodyUnion body; NACA foil;
void setup() { int n=(int)pow(2, 6)+2; // number of grid points size(800, 800); //sim window size Window view = new Window(n, n);
float xFoila = 20, xFoilb = 20, xFoilc = 20; float yFoila = 15, yFoilb = 25, yFoilc = 35; float resolution = 16, thickness = 0.2;
//body = new BodyUnion( new NACA(xFoila,yFoila,resolution, thickness,view), // new BodyUnion( new NACA(xFoilb,yFoilb,resolution, thickness,view), // new NACA(xFoilc,yFoilc,resolution, thickness,view) )); //three bodies will not move correctly
body = new BodyUnion( new NACA(xFoila, yFoila, resolution, thickness, view), new NACA(xFoilb, yFoilb, resolution, thickness, view)); //two bodies moving correctly }
void draw() { background(0); body.a.translate(0, 0.1); body.a.rotate(0.01); body.b.translate(0, 0.1); body.b.rotate(0.01);
body.update(); body.display(); }