FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   rotating a polygon
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: rotating a polygon  (Read 559 times)
kevinP

Email
rotating a polygon
« on: Jan 20th, 2004, 1:03pm »

Hi,
 
I tried the first homework assignment in the course notes posted here by baffo. I came up with this:
 
Code:

float angle = TWO_PI/3;  // angle (120 deg.) in radians
 
// tangent of an angle: ratio of the sine and cosine  
float tangent = tan(angle);
int x = radius/2;
 
// intersects vertex
line(center, center, center+x, center+x*tangent);
 
// tangent to face
stroke(200,200, 50);
line(center, center, center, center+x*tangent);
 
stroke(0, 0, 255);
line(center + x, center + x*tangent, center + 2*x, center);
line(center + 2*x, center, center + x, center - x*tangent);
line(center + x, center - x*tangent, center - x, center - x*tangent);
line(center - x, center - x*tangent, center - 2*x, center);
line(center - 2*x, center, center - x, center + x*tangent);
line(center - x, center + x*tangent, center + x, center + x*tangent);

 
How would I rotate this, say 15 degrees? So that I could specify the centerpoint, the radius of the circle that inscribes it, and an angle of rotation? Complete answer not needed, but a helpful hint is welcome.
 
Meanwhile I saw that I can simply this...
Code:

beginShape(POLYGON);  
vertex(center+x, center+x*tangent);  
vertex(center+2*x, center);  
vertex(center+x, center-x*tangent);
vertex(center-x, center-x*tangent);
vertex(center-2*x, center);
vertex(center-x, center+x*tangent);
endShape();
 
-K
« Last Edit: Jan 20th, 2004, 1:12pm by kevinP »  

Kevin Pfeiffer
Koenie

170825270170825270koeniedesign WWW Email
Re: rotating a polygon
« Reply #1 on: Jan 20th, 2004, 8:25pm »

You can simply use the Processing function called rotate(). You can find it in the reference here: http://proce55ing.net/reference/rotate_.html
 
Koenie
 

http://koeniedesign.com
kevinP

Email
Re: rotating a polygon
« Reply #2 on: Jan 27th, 2004, 10:40pm »

From the reference page for rotate():
"Positive numbers rotate objects in a counterclockwise direction."
 
But it seems to me that in my case this is working just the opposite...
Code:

  translate(width/2, width/2);
  rotate(2 * PI * 0.25);  //  

 
I expected that this would give me a 90 degree counterclockwise rotation, but it looks to me more like 90 degrees clockwise... ?
 
-K
 

Kevin Pfeiffer
benelek

35160983516098 WWW Email
Re: rotating a polygon
« Reply #3 on: Jan 27th, 2004, 11:51pm »

umm, the number 2*PI*0.25 gives half-PI radians, or (positive) 90 degrees. so the rotation occurs 90 degrees in the positive direction, which is clockwise in Processing. If you want to rotate the same amount counter-clockwise, use rotate( -0.5*PI ).
 
kevinP

Email
Re: rotating a polygon
« Reply #4 on: Jan 29th, 2004, 11:59pm »

Hi benelek,
 
on Jan 27th, 2004, 11:51pm, benelek wrote:
umm, the number 2*PI*0.25 gives half-PI radians, or (positive) 90 degrees. so the rotation occurs 90 degrees in the positive direction, which is clockwise in Processing. If you want to rotate the same amount counter-clockwise, use rotate( -0.5*PI ).

 
So is the Processing reference wrong, or did (do) I misunderstand it
 
-K
 

Kevin Pfeiffer
REAS


WWW
Re: rotating a polygon
« Reply #5 on: Jan 30th, 2004, 1:55am »

well...
the reference is incorrect. imagine that.
i'll fix it up.
 
K Pfeiffer
Guest
Email
Re: rotating a polygon
« Reply #6 on: Jan 30th, 2004, 9:44am »

You've got a tough audience here.
 
(But seriously, I just wanted to make sure that there wasn't some subtle point I had not caught).
 
-K
 
REAS


WWW
Re: rotating a polygon
« Reply #7 on: Jan 30th, 2004, 11:49am »

it's amazing, actually. that reference has been up for over a year and this is the first i've heard the problem. anyway, it's fixed now...
 
+ casey
 
Pages: 1 

« Previous topic | Next topic »