MATLAB: Creating a shape with varying arcs

arccircleMATLABpiecewiseplot

I would like to create a circle-like shape, but with various arcs along the circumference. A better way to explain this is just explain an example.
For example, I want to start with a circle that has a radius of 2 inches, have it gradually grow out to 3 inches over "x" radians, stay at 3 inches for "y" radians, and then return to 2 inches over "z" radians. Is this possible to plot in MATLAB? I am not sure how I would go about getting equations for those arcs and putting them together in a piecewise fashion to display continuously. The center of this circle is irrelevant to the problem, so for simplicity I will say the center of the BASE circle (the 2 in circular arc) is the origin. Picture for reference:

Best Answer

Note that 'smoothly' might not mean what you think it means: depending on your relative radii, you might get a change in concavity even with a "smooth" (continuous derivative) change in radius as a function of angle.
See if the below helps:
r1 = 2;
r2 = 3;
x1 = 4*pi/6; % r = r1
x2 = 2*pi/6; % r 'smoothly' increases
x3 = 3*pi/6; % r = r2
x4 = 2*pi - (x1 + x2 + x3); % r 'smoothly' decreases
t_table = cumsum([ 0, x1, x2, x3, x4, x1]); % note extra wrap-around entry to keep pchip smooth
r_table = [r1, r1, r2, r2, r1, r1];
n = 1000;
method = {'linear', 'pchip', 'spline'};
theta = linspace(0, 2*pi, n + 1);
%radius = interp1(t_table, r_table, theta, 'linear');
for k = 1:numel(method)
radius = interp1(t_table, r_table, theta, method{k});
hf{k} = figure('WindowStyle', 'Docked');
ha{k}(1) = subplot(2, 1, 1);
plot(theta, radius);
xlabel('\theta [rad]')
ylabel('r [u]')
axis([0, 2*pi, 0, r2*1.1])
grid('on')
ha{k}(2) = subplot(2, 1, 2);
plot(radius.*cos(theta), radius.*sin(theta));
title(['Cam Shape (', method{k}, ')'])
axis('equal')
grid('on')
axis([-1, 1, -1, 1]*r2*1.1)
end
(I think keeping a convex shape will depend on if your second region of [larger] constant radius lies within the cone/triangle defined by the two tangents at either end of your first region of [smaller] constant radius.)