Creating a shape with varying arcs?
4 ビュー (過去 30 日間)
古いコメントを表示
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:
0 件のコメント
採用された回答
arich82
2015 年 3 月 6 日
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.)
0 件のコメント
その他の回答 (1 件)
Giorgos Papakonstantinou
2015 年 3 月 6 日
If I understood correctly you mean a spiral. Here's one way then:
turns=5;
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
X=sin(theta).*r;
Y=cos(theta).*r;
plot(X,Y)
axis square
Of course you can adjust the radians as you wish.
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!