function [R,np,len] = rhodonea(k,b,N)
% Rhodonea curve of order k, with equation [x,y]=b·cos(k·u)*[cos(u),sin(u)], 
% Input:
%   k      : Order of the curve (integer)
%   b      : Size of the rhodonea
%   N      : Number of points
% Output:
%   P(2,N) : Points of the rhodonea curve
%   np     : Number of petals of the rhodonea
%   len    : Length of the rhodonea
% Usage:  
%   [P,np]=rhodonea(k,b,N)

% Find number of petals and angular grid
if mod(k,2)==0
  np = 2*k;
  u = linspace(0,2*pi,N);
else
  np = k;
  u = linspace(0,pi,N);
end

% Find curve points
r = b*cos(k*u);
R = [r.*cos(u);r.*sin(u)];

% Find curve length
dR = R(:,2:N)-R(:,1:N-1);  % vector increments
dl = sqrt(sum(dR.^2));     % length increments
len = sum(dl);

end
