Formulating a part of a given circle
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to create bumps in Matlab by providing only two inputs (h=61, L=293.69) as shown in the picture. However, for this I need to formulate the parts that appear in the picture (blue and orange). I know these parts are formulatable because they are all actually part of a circle. But I don't know which circle to associate these blue and orange parts with and how to connect h and L.
Any thoughts?
Thanks.
댓글 수: 0
채택된 답변
Mathieu NOE
2023년 6월 7일
hello
try this
i let you double check that the segment has only unique values on the x axis and do match L and h parameters :
>> xx(end)-L
ans = 0
>> max(yy)-h
ans = 0
h=61;
L=293.69;
% circle radius and angle
R = L^2/(16*h) + h/4;
theta = asin(L/(4*R));
th = linspace(0,theta,25);
% left blue section
xb = R*sin(th);
yb = R*(1-cos(th));
% left orange section (do not duplicate the connecting point)
xo = L/2 - xb(end-1:-1:1);
yo = h - yb(end-1:-1:1);
figure
plot(0,0,'dk',xb,yb,'b*-',L/4,h/2,'dk',xo,yo,'r*-',L/2,h,'dk','markersize',15)
% merge both segments (to have the entire left half bump)
xl = [xb xo];
yl = [yb yo];
figure
plot(xl,yl,'*-')
% create mirror right half bump and merge
% (do not duplicate the connecting point)
xr = L - xl(end-1:-1:1);
yr = yl(end-1:-1:1);
xx = [xl xr];
yy = [yl yr];
figure
plot(xx,yy,'*-')
댓글 수: 0
추가 답변 (1개)
John D'Errico
2023년 6월 7일
편집: John D'Errico
2023년 6월 7일
Drawing circular arcs here seems a bit unnecessary, since there is no need for it. You seem to be just looking for the basic shape, and the esiest way to do it is this way. Far better to just use a pair of cubic segments. That is, find a cubic polynomial that goes from 0 to 1, on the interval [0,1], AND has zero first derivatives at 0 and 1. Once we have that polynomial segment, then the rest is trivial. I could do it using pencil and paper, having done exersizes like this long ago. But this is a MATLAB forum, after all.
syms t a b c d
y(t) = a + b*t + c*t^2 + d*t^3;
dy(t) = diff(y,t);
sol = solve(y(0) == 0,y(1) == 1,dy(0) == 0,dy(1) == 0,[a,b,c,d])
y(t) = subs(y,[a,b,c,d],[sol.a,sol.b,sol.c,sol.d])
PLOT y.
fplot(y,[0,1])
That has the essential shape of part of the curve you want, but over a fixed domain.
Y(t) = piecewise(t<-1,0,-1<=t<0,y(t+1),0<=t<1,y(1-t),t>1,0)
fplot(Y,[-1,1])
So it is zero everywhere, except between -1 and 1. It has a slope of zero at -1 and 1, also at 0. And it has inflection points at -1/2 and 1/2. We can show that easily enough.
subs(diff(Y,t,2),[-1/2,1/2])
So the second derivatives are zero at +/- 1/2, thus an inflection point.
The curve looks a little different than the circular arcs, because of the aspect ratio of that plot. Your plor was much wider than it was high.
Can you use this function to draw your bumps? First, I'll make a simple MATLAB anonynmous function.
bump01 = @(t) (abs(t)<=1).*((t<0).*(3*(t+1).^2 - 2*(t+1).^3) + (t>=0).*(3*(t-1).^2 + 2*(t-1).^3));
bump = @(x,height,center,width) height*bump01((x-center)/(width/2));
fplot(@(x) bump(x,61,0,293),[-150,150])
grid on
Yes, we could have done the same using arcs of a circle. But do you really need that? I've given you a simple function in the bump function, that you can use for any center, height, and width. ANd you can form composites of mutiple bumps.
For example:
fplot(@(x) bump(x,10,25,20) + bump(x,5,10,30),[0,50])
Ok. COULD you do this with circular arcs? Now we need to have four arcs. That makes things slightly more complicated. Not hugely so. The trick is similar, in realizing that we really only need ONE circular arc! And then we will work with that arc, translating, transposing, and generally flipping it around.
The circular arc we want is exactly one eigth of a circle. Again, we can work with syms to develop the idea first.
syms X
Yarc(X) = 1 + (sqrt(1 - (X/2)^2)-1)/(1-sqrt(sym(3))/2)
fplot(Yarc,[0,1])
So now we have one circular arc, exactly one eigth of a circle, that maps [0,1] iinto [1,0]. We can now transform this arc into a similar one, by flipping it around. In fact, we don't really need to do much.
fplot(Yarc,[-1,0])
We can get the other pieces by more simple flips, but in the end, you will need to do more work. Just use the simple cubic segments.
댓글 수: 2
Mathieu NOE
2023년 6월 8일
I don't know why my suggestion was "silly" (I see that word disappearing after some time) as the title on this post seems to call for that solution (Formulating a part of a given circle)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!