필터 지우기
필터 지우기

Creating a shape with varying arcs?

조회 수: 1 (최근 30일)
Tyler
Tyler 2015년 3월 6일
답변: arich82 2015년 3월 6일
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:

채택된 답변

arich82
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.)

추가 답변 (1개)

Giorgos Papakonstantinou
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.
  댓글 수: 1
Tyler
Tyler 2015년 3월 6일
편집: Tyler 2015년 3월 6일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Visual Exploration에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by