We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › RESOLVED: how draw circles with bezier curves
Page Index Toggle Pages: 1
RESOLVED: how draw circles with bezier curves (Read 756 times)
RESOLVED: how draw circles with bezier curves
Mar 22nd, 2008, 8:55am
 
Hello,

I wrote a fonction that sould create a sort of diamond shape composed of 4 quarters of circles, I drew it in photoshop first to be sure of the positions of anchor and control points here is how it should look:

http://kazah.free.fr/processing/forme_lise.jpg

but in processing it looks like that:

http://kazah.free.fr/processing/forme_processing.png

It is a problem because we will use it as a pattern and it should create circles when applied to a grid, now it makes rouded corners squares...

any idea?

here is my code

int Ax and int Ay are the coordinates of the first anchor point, the top point of the shape, int taille is the variable that will determine the size of the shape
================================

void setup() {
 size(600, 600);
 noLoop();
 smooth();
noFill();
strokeWeight(1);
}

void draw() {
lise(width/2,(height/4),60);
}



void lise (int Ax, int Ay, int taille) {


beginShape();
 vertex(Ax, Ay);
 bezierVertex(Ax, Ay-taille, Ax, Ay-taille, Ax+taille, Ay-taille);
 bezierVertex( Ax, Ay-taille, Ax, Ay-taille,Ax, Ay-(taille)*2);
 bezierVertex(Ax, Ay-taille, Ax, Ay-taille, Ax-taille, Ay-taille);
 bezierVertex(Ax, Ay-taille, Ax, Ay-taille, Ax, Ay );
 endShape();

endShape();
}

=======================================================
Re: Bezier vertex doesnt draw the shape it should.
Reply #1 - Mar 22nd, 2008, 1:07pm
 
I've got some bad news, you're gonna have a lot of trouble(read as impossible) trying to make a circular shape with 3 point beziers.

How about thinking of the problem the other way round? Draw circles and let those define the diamonds?

this is the closest I can get (I'm not sure if it's even symmetrical
Quote:
beginShape();
 vertex(Ax, Ay);
 bezierVertex(Ax, Ay-taille, Ax+(taille), Ay-taille, Ax+taille, Ay-taille);
 bezierVertex( Ax, Ay-taille, Ax, Ay-taille*2,Ax, Ay-(taille)*2);
 bezierVertex(Ax, Ay-taille, Ax-taille, Ay-taille, Ax-taille, Ay-taille);
 bezierVertex(Ax, Ay-taille, Ax, Ay-taille/2, Ax, Ay );
 endShape();
 stroke(255);
endShape();
Re: Bezier vertex doesnt draw the shape it should.
Reply #2 - Mar 22nd, 2008, 6:39pm
 
thanks, it IS close!!!

as to drawing the circles, the thing is first the diamonds are in a grid and we see the circles at first but after they move aound when the grid is disrupted by a video capture. I am helping one of my students actually for her diploma project, and all her graphic design work uses this shape and now we work on a video installation, where the shapes size and movements will de determined by a dancer performing in front of the screen... actually we have the other parts kindof settled but we can't draw the shape right which I thought was the easy part...
Re: Bezier vertex doesnt draw the shape it should.
Reply #3 - Mar 22nd, 2008, 6:57pm
 
I just found something...with some magic number...

"The right value of kappa will draw a curve that is as close to a quadrant of a circle as we can get. It is my contention that we get the closest to a real circle if we draw the one curve with properties already discussed, and with the center point of the curve lying at the same point the center point of the circumference of a true quadrant of a circle would lie.
   I am not going to bore you with the details of deriving the value of such a kappa. I will just say that:

kappa = 0.5522847498"

http://www.whizkidtech.redprince.net/bezier/circle/

I try this and let you know, if tha approximation is really close, it can be of interesting use!
Draw circle  with bezier curves
Reply #4 - Mar 22nd, 2008, 10:01pm
 
Works!!!!!!!!

Here is how to draw a vary close ("one part in one thousand error would be one pixel on a screen circle of 14 inches at 73 DPI. It would be just over one pixel per inch on a 1200 DPI printer. ") approximation of a circle with bezier curves:

http://www.whizkidtech.redprince.net/bezier/circle/

now my shape looks good:

http://kazah.free.fr/processing/lise_good.png


here is the code

void setup() {
 size(600, 600);
 noLoop();
 smooth();
 noFill();
 strokeWeight(1);
}

void draw() {

 
 diamond(300,300,50);
}

void diamond (int ox, int oy, int rayon) {
 //kappa chiffre permettant de simuler des cercles avec des courbes de bezier
 //explication kappa:http://www.whizkidtech.redprince.net/bezier/circle/
 float kappa;
 kappa=(4.0 * (sqrt(2.0) - 1.0) / 3.0);
 //segment=longeur des segments reiant point d'ancrage a point de contrtole
 float segment;
 segment=rayon*kappa;
 //
  bezier(ox, oy, ox, oy-segment, (ox-rayon)+segment, oy-rayon, ox-rayon, oy-rayon);
 //
 bezier(ox-rayon, oy-rayon,(ox-rayon)+segment, oy-rayon,ox,oy-(rayon*2)+segment,ox,oy-(rayon*2));
//
 bezier(ox,oy-(rayon*2),ox,oy-(rayon*2)+segment,(ox+rayon)-segment,oy-rayon, ox+rayon,oy-rayon);
 //  
 bezier(ox+rayon,oy-rayon,(ox+rayon)-segment,oy-rayon,ox, oy-segment,ox,oy);
}

Page Index Toggle Pages: 1