Polar Rose 2D offset

I'm having some trouble trying to plot a polar rose with a offset C of the equation
r(theta) = cos(k*theta) + C. I'm trying to plot this polar rose:
http://en.wikipedia.org/wiki/Polar_coordinate_system#/media/File:Cartesian_to_polar.gif

The polar equation can be:
r(theta) = cos(k * theta)
or
r(theta) = sin(k * theta)

The equation of the polar rose I want to draw is:
r(theta) = 2 + sin(6 * theta)

Ok, and the parametric equations will be:
x = C + sin(k * theta) * cos(theta)
y = C + sin(k * theta) * sin(theta)

In my Canvas(drawing area), my origin is not at the center of the screen, so I need to translate the rose to it. Ok, no big deal. Another point is that I need to scale the rose for it to be visible or it will be too small, but still no problem, this explains the: 100*. Here is my code, it is on C++ btw:

for ( float t = 0; t < PI_2; t+= 0.01 )
{
    r = Origin.get_x() + 100*(2+(sin(6*t) * cos(t)));
    h = Origin.get_y() + 100*(2+(sin(6*t) * sin(t)));
    point(r,h);
}

I know that I'm doing it wrong, because when I add the +2 which should be the C constant is not working the way I want to, It's just translating more and drawing a polar rose without an offset. How do I prevent the "extra translation" and draw it properly?

Upvotes: 1

Views: 932

Answers (1)

Edward Doolittle
Edward Doolittle

Reputation: 4100

x = r cos(theta), y = r sin(theta) so your parametric equations should be x(theta) = C * cos(theta) + sin(k*theta) * cos(theta) and y(theta) = C * sin(theta) + sin(k*theta) * sin(theta). You just forgot to multiply C by cos(theta) and by sin(theta) respectively.

Upvotes: 1

Related Questions