Creating a shape with varying arcs?

3 views (last 30 days)
Tyler on 6 Mar 2015
Answered: arich82 on 6 Mar 2015
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:

Accepted Answer

arich82 on 6 Mar 2015
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])
ha{k}(2) = subplot(2, 1, 2);
plot(radius.*cos(theta), radius.*sin(theta));
title(['Cam Shape (', method{k}, ')'])
axis([-1, 1, -1, 1]*r2*1.1)
(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.)

More Answers (1)

Giorgos Papakonstantinou
Giorgos Papakonstantinou on 6 Mar 2015
If I understood correctly you mean a spiral. Here's one way then:
theta = 0:pi/180:2*pi*turns;
r = 2*ones(size(theta));
r(theta>1 & theta<=4) = linspace(2, 3, sum(theta>1 & theta<=4)); % radius gradually grows from 1<theta<=4 rad
r(theta>4) = 3; % constant radius for 4 rad<theta<=6 rad
r(theta>6) = linspace(3, 20, sum(theta>6)); % radius gradually grows from 6 rad<theta
axis square
Of course you can adjust the radians as you wish.
  1 Comment
Tyler on 6 Mar 2015
Edited: Tyler on 6 Mar 2015
Thank you, I may able to apply this to what I was speaking of, but I actually just wanted essentially a circle with a lump on it, ie the radius of the circle is 2 inches for x_1 radians, part of it smoothly bumps out to 3 inches over x_2 radians, it remains at 3 inches for x_3 radians and then it smoothly returns to 2 inches and remains there for x_4 radians, where x_1 + x_2 + x_3 + x_4 = 2*pi.
I am trying to display the profile of a cam, similar to one that is found in the image below:
The oblong shape is essentially what I am attempting to create.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!