rose curves?

Hiya,

I am thinking of doing a project that traces a rose curve. I think I know the equasions for rose curves (yay internet) but I am not sure how to write it in OF as a draw.

http://curvebank.calstatela.edu/polar/polar.htm

the formula written is t = sin 4t on 0.2PI but I dont entirely know what’s happening.

Any hints would be very appreciated!!

These are called parametric ecuations or cuves
http://en.wikipedia.org/wiki/Parametric-equation , and that is beacuse they depend on just one parameter t.
This one is in polar coodinates, which describes all the plane with a radius r and an angle tetha
http://en.wikipedia.org/wiki/Polar-coordinate-system
The rule for translation to Cartesian coordinates (the one OF undestands) is:
x=r cos(tetha);
y=r sin(tetha);

Here is the code to paint a filled rose

  
  
void testApp::draw(){  
    ofSetColor(200,30,30);  
    int i;  
    float t,x,y;  
    ofSetPolyMode(OF_POLY_WINDING_NONZERO);  
    ofBeginShape();  
    while(i<360)  
      {  
        //r=sin(4t); is polar  
        //in x/y space:  
        //x=r cos(t);=>x=sin(4t)*cos(t)  
        //y=r sin(t);=>y=sin(4t)*sin(t)  
        t=PI*i/180;  
        ofVertex(300+50*sin(4*t)*cos(t),300+50*sin(4*t)*sin(t));  
       i++;  
      }  
    ofEndShape();  
}  
  

And with this one you can draw the outline

  
  
void testApp::draw(){  
    ofSetColor(200,30,30);  
    int i;  
    float t,x,y,xN,yN;  
    x=300;  
    y=300;  
    while(i<360)  
      {  
        //r=sin(4t); is polar  
        // in x/y space:  
        //x=r cos(t);=>x=sin(4t)*cos(t)  
        //y=r sin(t);=>y=sin(4t)*sin(t)  
        t=PI*i/180;  
        xN=300+50*sin(4*t)*cos(t);  
        yN=300+50*sin(4*t)*sin(t);  
        ofLine(x,y,xN,yN);  
        x=xN;  
        y=yN;  
        i++;  
      }  
}  
  

Both are center at (300,300) and have radius size of 50 pixels.
Now I supose the fun part is to animate it.

Cheers

== edit, I wrote this up and forgot to hit post yesterday and I’m doing it now anyways even though someone else already explained it and probably better than myself

The equation just looks like this:

  
  
p = amp*cos(petals*radian); // do the polar coordinates  
x = x0+p*cos(radian); // Cartesian i.e. x/y coords  
y = y0+p*sin(radian); // Cartesian i.e. x/y coords  
  

This draws the rose over several frames:

  
  
void testApp::setup() {	   
  
	prevx = prevy = degree = radian = x = y = 0.0f;  
	amp = 300; // size of the rose  
	x0 = y0 = 400; // this becomes the center  
	petals = 12; // number of petals  
	ofSetFrameRate(30);  
        ofSetBackgroundAuto(false);  
	ofBackground(122, 122, 122);  
  
	  
}  
  
void testApp::draw() {  
  
	if (degree<=360) {  
		radian = PI/180*(degree);  
		p = amp*cos(6*radian); //do the polar coordinates  
		x = x0+p*cos(radian); // convert to Cartesian  
		y = y0+p*sin(radian); // convert to Cartesian  
		ofLine(prevx, prevy, x, y); // draw  
		prevx = x;  
		prevy = y;  
		degree++;  
	} else {  
		degree = 0;  
		ofBackground(122, 122, 122);  
	}  
}  
  

There’s some more info and ideas here: http://mathworld.wolfram.com/Rose.html

Awesome guys, thanks! I gotta try this out :smiley:

Thank you very much :slight_smile: