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 › value from curve to control rotation
Page Index Toggle Pages: 1
value from curve to control rotation (Read 428 times)
value from curve to control rotation
Jul 12th, 2009, 1:34pm
 
Hello, in a program im working on im using a curve created with the library geomerative as a path for a graphical object movement.

I would like to control also the rotation of my graphical element with that curve .
In other words i want that the amount of rotation depends on where on the curve the graphical element is at. I want to that the graphical element can rotate following the shape of the curve. How can i do this? Do i need to calculate normals  for this? any hint?


Seb.
Re: value from curve to control rotation
Reply #1 - Jul 12th, 2009, 2:34pm
 
I don't know for Geomerative, although it probably offers similar facilities (and more). But in Processing you can use bezierTangent() (or curveTangent()) to know the direction on the curve.
Re: value from curve to control rotation
Reply #2 - Jul 13th, 2009, 6:45am
 
hi, ive made this example using bezierTangent, it works but im getting two  wierd behaivors. The first one is that my sphere appears in  front of the curve line and then it sometimes goes to the back.

my second wierd behaivor is that in the begining of the curve it seems to works well but when the ellipse is at the end of the line it stills rotating not following the curve.

Why are these problems comming? Do im doing anything bad?

there is my code

thanks in advance



Code:


import processing.opengl.*;



float aumenta = 0;

float x1;
float y1;
float cx1;
float cy1;
float cx2;
float cy2;
float x2;
float y2;



void setup() {
size(600, 300, OPENGL);

x1 = 0;
y1 = random(200);
cx1 = random(200);
cy1 = random(200);
cx2 = random(200);
cy2 = random(200);
x2 = random(200);
y2 = random(200);

}



void draw(){
background(250, 250 , 0);
noFill();


bezier(0, y1, cx1, cy1, cx2, cy2, 600, y2);
fill(255);

aumenta = aumenta + 0.003;

float x = bezierPoint(0, cx1, cx2, 600, aumenta);
float y = bezierPoint(y1, cy1, cy2, y2, aumenta);

float tx = bezierTangent(0, cx1, cx2, 600, aumenta);
float ty = bezierTangent(y1, cy1, cy2, y2, aumenta);

float a = atan2(ty, tx);
//a -= HALF_PI;

rotateX(a);
ellipse(x, y, 10, 25);
}





Page Index Toggle Pages: 1