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 › How to draw circle from points
Page Index Toggle Pages: 1
How to draw circle from points? (Read 1013 times)
How to draw circle from points?
Feb 24th, 2009, 2:21pm
 
Hello!

Can somebody give a hand with this?

I know it's almost pre mathematics, and this is why i'm asking, not good in it...

If i will place enough points around central point on the same direction each, they will create a circle. how can i calculate coordinates for every next point?

thanx!
Re: How to draw circle from points?
Reply #1 - Feb 24th, 2009, 3:08pm
 
This is trigonometry, circular functions, sine, cosine, tangent.

http://en.wikipedia.org/wiki/Trigonometry

Basically you should use the sine of a given angle as Y coordinate and the cosine of the same angle as X coordinate and then increment the angle. You may want to use a factor (multiplying both numbers by it) to control the circle size.
Beware that trigonometrical functions expect the angle as radians, you can convert using radians() function.

some thing like:

int x;
 void draw(){
if(x<360){x++;}
pushMatrix();
translate(width/2,height/2);// bring zero point to the center

stroke(0);

point (sin(radians(x))*50,cos(radians(x))*50);
point (sin(radians(x))*25,cos(radians(x))*25);

stroke(255);

point (sin(radians(x))*50,cos(radians(x))*25);//<ellipse
popMatrix();


}

Re: How to draw circle from points?
Reply #2 - Feb 24th, 2009, 7:40pm
 
Hi! Thank you for answer!
Actually i'm trying to understand how to rotate svg shape around it's center...

can you check my code please?


PShape bot;
 
void setup()
{
 size(500,500);
 smooth();
 frameRate(30);
 bot = loadShape("pum.svg");
}


void draw()
{
 background(200);
 
 translate(width/2, height/2);  
 
 shape(bot, 0, 0,100,100);
 bot.rotate(radians(1));
 
}

if i'm changing pshape mode to CENTER it is still rotating around left top corner...

how can i implement all those sin and cos thingies to to translate 0,0 point of shape so it will move around center of shape...
Page Index Toggle Pages: 1