project not drawing my vertex with calculated points
in
Programming Questions
•
6 months ago
Hello,
I am having troubles to make my "drawing" appear. the drawing uses points calculated in my class "Grondplan".
The method "snijPunten" is responsible for creating the points which should been drawn. And in my constructor are the conditions of where the points should go in. Since the result should be a polygon in a polygon.
I am new to processing. Am i missing an obvious point? or did i just completely mess up my code?
I have been trying and trying to make it work but i can't find where I have gone wrong.
ps you might notice "strange" names for my methodes and class, this is because i'm dutch and these are dutch words.
Thank you.
Grondplan grond = new Grondplan();
void setup()
{
size(600,600,P3D);
}
void draw()
{
background(242);
stroke(255,0,0);
strokeWeight(10);
grond.drawGrondplan();
line(0, 0, 0, width, height, 0);
}
class Grondplan
{
private float[] middelX = new float[15];
private float[] middelY = new float[15];
private float[] straal = new float[15];
private float[] snijVerX = new float[15];
private float[] snijVerY = new float[15];
private float[] snijKortX = new float[15];
private float[] snijKortY = new float[15];
private float HCX = 250;
private float HCY = 25;
private float HCR = 200;
private float x1;
private float x2;
private float y1;
private float y2;
public Grondplan()
{
middelX[0] = 250 + 200;
middelY[0] = 250;
straal[0] = 55;
float dist1;
float dist2;
float r;
for(int k = 1;k<15;k++)
{
r = random(30,61);
straal[k] = r;
snijPunten(k,true);
if (k < 2)
{
middelX[k] = x1;
middelY[k] = y1;
}
else
{
dist1 = dist(x1, y1, 0, middelX[k - 2], middelY[k - 2], 0);
dist2 = dist(x2, y2, 0, middelX[k - 2], middelY[k - 2], 0);
if(dist1<dist2)
{
middelX[k] = x1;
middelY[k] = y1;
}
else
{
middelX[k] = x2;
middelY[k] = y2;
}
}
snijPunten(k,false);
dist1 = dist(x1, y1, 0, HCX, HCY, 0);
dist2 = dist(x2, y2, 0, HCX, HCY, 0);
if(dist1<dist2)
{
snijVerX[k] = x2;
snijVerY[k] = y2;
snijKortX[k] = x1;
snijKortY[k] = y1;
}
if(dist2<dist1)
{
snijVerX[k] = x1;
snijVerY[k] = y1;
snijKortX[k] = x2;
snijKortY[k] = y2;
}
}
snijPuntenFinish();
dist1 = dist(x1, y1, 0, HCX, HCY, 0);
dist2 = dist(x2, y2, 0, HCX, HCY, 0);
if(dist1<dist2)
{
snijVerX[0] = x2;
snijVerY[0] = y2;
snijKortX[0] = x1;
snijKortY[0] = y1;
}
if(dist2<dist1)
{
snijVerX[0] = x1;
snijVerY[0] = y1;
snijKortX[0] = x2;
snijKortY[0] = y2;
}
}
public void snijPunten(int k, boolean hoofdCirkel)
{
float a;
float b;
float c;
float e;
float f;
float g;
float h;
float i;
float j;
float D;
float r2;
if(hoofdCirkel)
{
e = (-2) * HCX;
f = (-2) * HCY;
g = (-1) * sq(HCR) + sq(HCX) + sq(HCY);
r2 = random(25,straal[k-1]+straal[k]-5);
}
else
{
e = (-2) * middelX[k];
f = (-2) * middelY[k];
g = (-1) * sq(straal[k]) + sq(middelX[k]) + sq(middelY[k]);
r2 = straal[k-1];
}
a = (-2) * middelX[k-1];
b = (-2) * middelY[k-1];
c = (-1) * sq(r2) + sq(middelX[k-1]) + sq(middelY[k-1]);
h = sq(b - f) + sq(a - e);
i = a * (sq(b - f) + (sq(b) - (b * f))) - (e * (sq(b) - (b * f)));
j = (c - g) * (sq(b) - (b * f)) - sq(b * f) * c;
D = sq(i) + 4 * h * j;
x1 = (-i + sqrt(D)) / (2 * h);
x2 = (-i - sqrt(D)) / (2 * h);
y1 = ((a - e) * x1 + (c - g)) / (b - f);
y2 = ((a - e) * x2 + (c - g)) / (b - f);
}
public void snijPuntenFinish()
{
float a;
float b;
float c;
float e;
float f;
float g;
float h;
float i;
float j;
float D;
e = (-2) * middelX[14];
f = (-2) * middelY[14];
g = (-1) * sq(straal[14]) + sq(middelX[14]) + sq(middelY[14]);
;
a = (-2) * middelX[0];
b = (-2) * middelY[0];
c = (-1) * sq(straal[0]) + sq(middelX[0]) + sq(middelY[0]);
h = sq(b - f) + sq(a - e);
i = a * (sq(b - f) + (sq(b) - (b * f))) - (e * (sq(b) - (b * f)));
j = (c - g) * (sq(b) - (b * f)) - sq(b * f) * c;
D = sq(i) + 4 * h * j;
x1 = (-i + sqrt(D)) / (2 * h);
x2 = (-i - sqrt(D)) / (2 * h);
y1 = ((a - e) * x1 + (c - g)) / (b - f);
y2 = ((a - e) * x2 + (c - g)) / (b - f);
}
public float returnVerX(int i)
{
return snijVerX[i];
}
public float returnVerY(int i)
{
return snijVerY[i];
}
public float returnKortX(int i)
{
return snijKortX[i];
}
public float returnKortY(int i)
{
return snijKortY[i];
}
public void drawGrondplan()
{
beginShape();
for(int i=0;i<15;i++)
{
vertex(returnVerX(i),returnVerY(i),0);
}
beginContour();
for(int i=0;i<15;i++)
{
vertex(returnKortX(i),returnKortY(i),0);
}
endContour();
endShape(CLOSE);
}
}
I am having troubles to make my "drawing" appear. the drawing uses points calculated in my class "Grondplan".
The method "snijPunten" is responsible for creating the points which should been drawn. And in my constructor are the conditions of where the points should go in. Since the result should be a polygon in a polygon.
I am new to processing. Am i missing an obvious point? or did i just completely mess up my code?
I have been trying and trying to make it work but i can't find where I have gone wrong.
ps you might notice "strange" names for my methodes and class, this is because i'm dutch and these are dutch words.
Thank you.
Grondplan grond = new Grondplan();
void setup()
{
size(600,600,P3D);
}
void draw()
{
background(242);
stroke(255,0,0);
strokeWeight(10);
grond.drawGrondplan();
line(0, 0, 0, width, height, 0);
}
class Grondplan
{
private float[] middelX = new float[15];
private float[] middelY = new float[15];
private float[] straal = new float[15];
private float[] snijVerX = new float[15];
private float[] snijVerY = new float[15];
private float[] snijKortX = new float[15];
private float[] snijKortY = new float[15];
private float HCX = 250;
private float HCY = 25;
private float HCR = 200;
private float x1;
private float x2;
private float y1;
private float y2;
public Grondplan()
{
middelX[0] = 250 + 200;
middelY[0] = 250;
straal[0] = 55;
float dist1;
float dist2;
float r;
for(int k = 1;k<15;k++)
{
r = random(30,61);
straal[k] = r;
snijPunten(k,true);
if (k < 2)
{
middelX[k] = x1;
middelY[k] = y1;
}
else
{
dist1 = dist(x1, y1, 0, middelX[k - 2], middelY[k - 2], 0);
dist2 = dist(x2, y2, 0, middelX[k - 2], middelY[k - 2], 0);
if(dist1<dist2)
{
middelX[k] = x1;
middelY[k] = y1;
}
else
{
middelX[k] = x2;
middelY[k] = y2;
}
}
snijPunten(k,false);
dist1 = dist(x1, y1, 0, HCX, HCY, 0);
dist2 = dist(x2, y2, 0, HCX, HCY, 0);
if(dist1<dist2)
{
snijVerX[k] = x2;
snijVerY[k] = y2;
snijKortX[k] = x1;
snijKortY[k] = y1;
}
if(dist2<dist1)
{
snijVerX[k] = x1;
snijVerY[k] = y1;
snijKortX[k] = x2;
snijKortY[k] = y2;
}
}
snijPuntenFinish();
dist1 = dist(x1, y1, 0, HCX, HCY, 0);
dist2 = dist(x2, y2, 0, HCX, HCY, 0);
if(dist1<dist2)
{
snijVerX[0] = x2;
snijVerY[0] = y2;
snijKortX[0] = x1;
snijKortY[0] = y1;
}
if(dist2<dist1)
{
snijVerX[0] = x1;
snijVerY[0] = y1;
snijKortX[0] = x2;
snijKortY[0] = y2;
}
}
public void snijPunten(int k, boolean hoofdCirkel)
{
float a;
float b;
float c;
float e;
float f;
float g;
float h;
float i;
float j;
float D;
float r2;
if(hoofdCirkel)
{
e = (-2) * HCX;
f = (-2) * HCY;
g = (-1) * sq(HCR) + sq(HCX) + sq(HCY);
r2 = random(25,straal[k-1]+straal[k]-5);
}
else
{
e = (-2) * middelX[k];
f = (-2) * middelY[k];
g = (-1) * sq(straal[k]) + sq(middelX[k]) + sq(middelY[k]);
r2 = straal[k-1];
}
a = (-2) * middelX[k-1];
b = (-2) * middelY[k-1];
c = (-1) * sq(r2) + sq(middelX[k-1]) + sq(middelY[k-1]);
h = sq(b - f) + sq(a - e);
i = a * (sq(b - f) + (sq(b) - (b * f))) - (e * (sq(b) - (b * f)));
j = (c - g) * (sq(b) - (b * f)) - sq(b * f) * c;
D = sq(i) + 4 * h * j;
x1 = (-i + sqrt(D)) / (2 * h);
x2 = (-i - sqrt(D)) / (2 * h);
y1 = ((a - e) * x1 + (c - g)) / (b - f);
y2 = ((a - e) * x2 + (c - g)) / (b - f);
}
public void snijPuntenFinish()
{
float a;
float b;
float c;
float e;
float f;
float g;
float h;
float i;
float j;
float D;
e = (-2) * middelX[14];
f = (-2) * middelY[14];
g = (-1) * sq(straal[14]) + sq(middelX[14]) + sq(middelY[14]);
;
a = (-2) * middelX[0];
b = (-2) * middelY[0];
c = (-1) * sq(straal[0]) + sq(middelX[0]) + sq(middelY[0]);
h = sq(b - f) + sq(a - e);
i = a * (sq(b - f) + (sq(b) - (b * f))) - (e * (sq(b) - (b * f)));
j = (c - g) * (sq(b) - (b * f)) - sq(b * f) * c;
D = sq(i) + 4 * h * j;
x1 = (-i + sqrt(D)) / (2 * h);
x2 = (-i - sqrt(D)) / (2 * h);
y1 = ((a - e) * x1 + (c - g)) / (b - f);
y2 = ((a - e) * x2 + (c - g)) / (b - f);
}
public float returnVerX(int i)
{
return snijVerX[i];
}
public float returnVerY(int i)
{
return snijVerY[i];
}
public float returnKortX(int i)
{
return snijKortX[i];
}
public float returnKortY(int i)
{
return snijKortY[i];
}
public void drawGrondplan()
{
beginShape();
for(int i=0;i<15;i++)
{
vertex(returnVerX(i),returnVerY(i),0);
}
beginContour();
for(int i=0;i<15;i++)
{
vertex(returnKortX(i),returnKortY(i),0);
}
endContour();
endShape(CLOSE);
}
}
1