Hi, I am new to processing and am currently trying to program a little spring.
The point is, whenever I try to run the code I get:
"The constructor DualSpring(PVector, PVector, float, float, float, float, float, float, float)" is undefined.
After looking for info in google I found people who had problems using the "this" keyword which was the source of the problem in most cases. But I have never used that keyword and yet get this error.
Here I provide every line of code in this program hoping someone will find the cause, however, the lines related to the problem should be the three I highlighted.
Thanks for your help.
//Springs declaration
DualSpring s1;
DualSpring s2;
void setup()
{
size(720, 480);
//Initial springs setup
PVector c1 = new PVector(0.25 * width, 20, 0.0);
PVector c2 = new PVector(0.25 * width, 100, 0.0);
float m1 = 2.0;
float m2 = m1;
float r1 = 20.0;
float r2 = r2;
float sl = 80.0;
float s = 0.2;
float d = 0.2;
//This is the constructor declaration, it can also be found in the DualSpring class
//DualSpring(PVector c1, PVector c2, float m1, float m2, float r1, float r2, float sl, float s, float d)
s1 = new DualSpring(c1, c2, m1, m2, r1, r2, sl, s, d);
//I also tried creating the PVector object within the params list, however the result was the same
//s1 = new DualSpring(new PVector(0.25 * width, 20, 0.0), new PVector(0.25 * width, 100, 0.0), m1, m2, r1, r2, sl, s, d);
//Here I create the second spring for the test I wanted to perform
c1.set(0.75 * width, 20, 0.0);
c2.set(0.75 * width, 100, 0.0);
m1 = 2.0;
m2 = m1;
r1 = 20;
r2 = r1;
sl = 80;
s = 0.2;
d = 0.2;
s2 = new DualSpring(c1, c2, m1, m2, r1, r2, sl, s, d);
}
void draw()
{
background(255);
s1.drawSpring();
s2.drawSpring();
}
class DualSpring
{
float stepSize = 0.1;
float gravity = 1.5;
PhyParticle masses;
PhyParticle sMass1;
PhyParticle sMass2;
PVector centers;
PVector center1;
PVector center2;
float radius1;
float radius2;
float sLength;
float stiffness;
float damping;
DualSpring(PVector c1, PVector c2, float m1, float m2, float r1, float r2, float sl, float s, float d)
{
masses = new masses[2];
centers = new PVector[2];
centers[0] = new PVector();
centers[1] = new PVector();
centers[0].set(c1);
centers[1].set(c2);
masses[0] = new PhyParticle(centers[0], m1);
masses[1] = new PhyParticle(centers[1], m2);
radius1 = r1;
radius2 = r2;
sLength = sl;
stiffness = s;
damping = d;
}
void directMove(int index, float dx, float dy)
{
//index values: 1, 2.
if(index == 1)
{
masses[0].acl.x = -((stiffness * 1.0 * dx) + (damping * masses[0].vel.x)) / masses[0].mass;
masses[0].acl.y = -((stiffness * 1.0 * dy) + (damping * masses[0].vel.y)) / masses[0].mass;
masses[0].vel.x = masses[0].vel.x + (masses[0].acl.x * stepSize);
masses[0].vel.y = masses[0].vel.y + (masses[0].acl.y * stepSize);
masses[0].pos.x = masses[0].pos.x + (masses[0].vel.x * stepSize);
masses[0].pos.y = masses[0].pos.y + (masses[0].vel.y * stepSize);
}
else if(index == 2)
{
masses[1].acl.x = -((stiffness * 1.0 * dx) + (damping * masses[1].vel.x)) / masses[1].mass;
masses[1].acl.y = -((stiffness * 1.0 * dy) + (damping * masses[1].vel.y)) / masses[1].mass;
masses[1].vel.x = masses[1].vel.x + (masses[1].acl.x * stepSize);
masses[1].vel.y = masses[1].vel.y + (masses[1].acl.y * stepSize);
masses[1].pos.x = masses[1].pos.x + (masses[1].vel.x * stepSize);
masses[1].pos.y = masses[1].pos.y + (masses[1].vel.y * stepSize);
}
}
void inverseMove(int index, float dx, float dy)
{
//index values: 1, 2.
if(index == 1)
{
masses[1].acl.x = -((stiffness * 1.0 * dx) + (damping * masses[1].vel.x)) / masses[1].mass;
masses[1].acl.y = -((stiffness * 1.0 * dy) + (damping * masses[1].vel.y)) / masses[1].mass;
masses[1].vel.x = masses[1].vel.x + (masses[1].acl.x * stepSize);
masses[1].vel.y = masses[1].vel.y + (masses[1].acl.y * stepSize);
masses[1].pos.x = masses[1].pos.x + (masses[1].vel.x * stepSize);
masses[1].pos.y = masses[1].pos.y + (masses[1].vel.y * stepSize);
}
else if(index == 2)
{
masses[0].acl.x = -((stiffness * 1.0 * dx) + (damping * masses[0].vel.x)) / masses[0].mass;
masses[0].acl.y = -((stiffness * 1.0 * dy) + (damping * masses[0].vel.y)) / masses[0].mass;
masses[0].vel.x = masses[0].vel.x + (masses[0].acl.x * stepSize);
masses[0].vel.y = masses[0].vel.y + (masses[0].acl.y * stepSize);
masses[0].pos.x = masses[0].pos.x + (masses[0].vel.x * stepSize);
masses[0].pos.y = masses[0].pos.y + (masses[0].vel.y * stepSize);
}
}
void drawSpring()
{
drawLines();
drawMasses();
}
void drawLines()
{
float x1, y1;
float x2, y2;
x1 = masses[0].pos.x;
y1 = masses[0].pos.y;
x2 = masses[1].pos.x;
y2 = masses[1].pos.y;
stroke(0);
line(x1, y1, x2, y2);
}
void drawMasses()
{
float x1, y1;
float x2, y2;
x1 = masses[0].pos.x;
y1 = masses[0].pos.y;
x2 = masses[1].pos.x;
y2 = masses[1].pos.y;
stroke(0);
fill(0);
ellipse(x1, y1, radius1, radius1);
ellipse(x2, y2, radius2, radius2);
}
int hoverSpring(float x, float y)
{
float distance;
if(PVector.dist(new PVector(x, y, 0), new PVector(masses[0].pos.x, masses[0].pos.y, 0)) < radius1)
{
return 1;
}
else if(PVector.dist(new PVector(x, y, 0), new PVector(masses[1].pos.x, masses[1].pos.y, 0)) < radius2)
{
return 2;
}
}
}
class PhyParticle
{
PVector pos;
PVector vel;
PVector acl;
PVector force;
float mass;
phyParticle(PVector p, float m)
{
pos = new PVector();
vel = new PVector();
acl = new PVector();
force = new PVector();
//pos = equalVec(pos, p);
pos.set(p);
mass = m;
}
}
The point is, whenever I try to run the code I get:
"The constructor DualSpring(PVector, PVector, float, float, float, float, float, float, float)" is undefined.
After looking for info in google I found people who had problems using the "this" keyword which was the source of the problem in most cases. But I have never used that keyword and yet get this error.
Here I provide every line of code in this program hoping someone will find the cause, however, the lines related to the problem should be the three I highlighted.
Thanks for your help.
//Springs declaration
DualSpring s1;
DualSpring s2;
void setup()
{
size(720, 480);
//Initial springs setup
PVector c1 = new PVector(0.25 * width, 20, 0.0);
PVector c2 = new PVector(0.25 * width, 100, 0.0);
float m1 = 2.0;
float m2 = m1;
float r1 = 20.0;
float r2 = r2;
float sl = 80.0;
float s = 0.2;
float d = 0.2;
//This is the constructor declaration, it can also be found in the DualSpring class
//DualSpring(PVector c1, PVector c2, float m1, float m2, float r1, float r2, float sl, float s, float d)
s1 = new DualSpring(c1, c2, m1, m2, r1, r2, sl, s, d);
//I also tried creating the PVector object within the params list, however the result was the same
//s1 = new DualSpring(new PVector(0.25 * width, 20, 0.0), new PVector(0.25 * width, 100, 0.0), m1, m2, r1, r2, sl, s, d);
//Here I create the second spring for the test I wanted to perform
c1.set(0.75 * width, 20, 0.0);
c2.set(0.75 * width, 100, 0.0);
m1 = 2.0;
m2 = m1;
r1 = 20;
r2 = r1;
sl = 80;
s = 0.2;
d = 0.2;
s2 = new DualSpring(c1, c2, m1, m2, r1, r2, sl, s, d);
}
void draw()
{
background(255);
s1.drawSpring();
s2.drawSpring();
}
class DualSpring
{
float stepSize = 0.1;
float gravity = 1.5;
PhyParticle masses;
PhyParticle sMass1;
PhyParticle sMass2;
PVector centers;
PVector center1;
PVector center2;
float radius1;
float radius2;
float sLength;
float stiffness;
float damping;
DualSpring(PVector c1, PVector c2, float m1, float m2, float r1, float r2, float sl, float s, float d)
{
masses = new masses[2];
centers = new PVector[2];
centers[0] = new PVector();
centers[1] = new PVector();
centers[0].set(c1);
centers[1].set(c2);
masses[0] = new PhyParticle(centers[0], m1);
masses[1] = new PhyParticle(centers[1], m2);
radius1 = r1;
radius2 = r2;
sLength = sl;
stiffness = s;
damping = d;
}
void directMove(int index, float dx, float dy)
{
//index values: 1, 2.
if(index == 1)
{
masses[0].acl.x = -((stiffness * 1.0 * dx) + (damping * masses[0].vel.x)) / masses[0].mass;
masses[0].acl.y = -((stiffness * 1.0 * dy) + (damping * masses[0].vel.y)) / masses[0].mass;
masses[0].vel.x = masses[0].vel.x + (masses[0].acl.x * stepSize);
masses[0].vel.y = masses[0].vel.y + (masses[0].acl.y * stepSize);
masses[0].pos.x = masses[0].pos.x + (masses[0].vel.x * stepSize);
masses[0].pos.y = masses[0].pos.y + (masses[0].vel.y * stepSize);
}
else if(index == 2)
{
masses[1].acl.x = -((stiffness * 1.0 * dx) + (damping * masses[1].vel.x)) / masses[1].mass;
masses[1].acl.y = -((stiffness * 1.0 * dy) + (damping * masses[1].vel.y)) / masses[1].mass;
masses[1].vel.x = masses[1].vel.x + (masses[1].acl.x * stepSize);
masses[1].vel.y = masses[1].vel.y + (masses[1].acl.y * stepSize);
masses[1].pos.x = masses[1].pos.x + (masses[1].vel.x * stepSize);
masses[1].pos.y = masses[1].pos.y + (masses[1].vel.y * stepSize);
}
}
void inverseMove(int index, float dx, float dy)
{
//index values: 1, 2.
if(index == 1)
{
masses[1].acl.x = -((stiffness * 1.0 * dx) + (damping * masses[1].vel.x)) / masses[1].mass;
masses[1].acl.y = -((stiffness * 1.0 * dy) + (damping * masses[1].vel.y)) / masses[1].mass;
masses[1].vel.x = masses[1].vel.x + (masses[1].acl.x * stepSize);
masses[1].vel.y = masses[1].vel.y + (masses[1].acl.y * stepSize);
masses[1].pos.x = masses[1].pos.x + (masses[1].vel.x * stepSize);
masses[1].pos.y = masses[1].pos.y + (masses[1].vel.y * stepSize);
}
else if(index == 2)
{
masses[0].acl.x = -((stiffness * 1.0 * dx) + (damping * masses[0].vel.x)) / masses[0].mass;
masses[0].acl.y = -((stiffness * 1.0 * dy) + (damping * masses[0].vel.y)) / masses[0].mass;
masses[0].vel.x = masses[0].vel.x + (masses[0].acl.x * stepSize);
masses[0].vel.y = masses[0].vel.y + (masses[0].acl.y * stepSize);
masses[0].pos.x = masses[0].pos.x + (masses[0].vel.x * stepSize);
masses[0].pos.y = masses[0].pos.y + (masses[0].vel.y * stepSize);
}
}
void drawSpring()
{
drawLines();
drawMasses();
}
void drawLines()
{
float x1, y1;
float x2, y2;
x1 = masses[0].pos.x;
y1 = masses[0].pos.y;
x2 = masses[1].pos.x;
y2 = masses[1].pos.y;
stroke(0);
line(x1, y1, x2, y2);
}
void drawMasses()
{
float x1, y1;
float x2, y2;
x1 = masses[0].pos.x;
y1 = masses[0].pos.y;
x2 = masses[1].pos.x;
y2 = masses[1].pos.y;
stroke(0);
fill(0);
ellipse(x1, y1, radius1, radius1);
ellipse(x2, y2, radius2, radius2);
}
int hoverSpring(float x, float y)
{
float distance;
if(PVector.dist(new PVector(x, y, 0), new PVector(masses[0].pos.x, masses[0].pos.y, 0)) < radius1)
{
return 1;
}
else if(PVector.dist(new PVector(x, y, 0), new PVector(masses[1].pos.x, masses[1].pos.y, 0)) < radius2)
{
return 2;
}
}
}
class PhyParticle
{
PVector pos;
PVector vel;
PVector acl;
PVector force;
float mass;
phyParticle(PVector p, float m)
{
pos = new PVector();
vel = new PVector();
acl = new PVector();
force = new PVector();
//pos = equalVec(pos, p);
pos.set(p);
mass = m;
}
}
1