Average of two closed curves

7 ビュー (過去 30 日間)
Jullienne Franz
Jullienne Franz 2019 年 3 月 16 日
コメント済み: Jullienne Franz 2019 年 3 月 16 日
Dear everyone,
Is there a way in Matlab to average two closed curves? say I want to take the average of a unit square and a unit circle? How do I do this in Matlab?
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 3 月 16 日
It would be better to undestand the problem, if you show the same in mathematical expression?
KSSV
KSSV 2019 年 3 月 16 日
Read about mean

サインインしてコメントする。

回答 (2 件)

Stephan
Stephan 2019 年 3 月 16 日
編集済み: Stephan 2019 年 3 月 16 日
Hi,
try:
% Calculate Parts to 90°
angle1 = linspace(0,pi/4,180)';
% Radius of circle = length of square = 1
r = 1;
% Calculate the mean
r_mean = ((sqrt(r.*tan(angle1).^2 +r.^2))+r)./2;
% Calculate the coordinates
x = [r_mean.*cos(angle1); r_mean.*cos(angle1)];
y = [r_mean.*sin(angle1); -r_mean.*sin(angle1)];
% Build the vectors to plot
xvals = [x; -x; y; y];
yvals = [y; y; -x; x];
% plot
scatter(xvals,yvals)
a further possibility is working with polyshape objects:
% construct the polyshape object
poly = polyshape(xvals, yvals);
pgon = simplify(convhull(poly));
% construct the square
rect = polyshape([-1 1 1 -1], [-1 -1 1 1]);
% construct the circle
t = 0:0.05:2*pi;
x1 = cos(t);
y1 = sin(t);
circ = polyshape(x1,y1);
% plot them all
hold on
plot(rect)
plot(pgon)
plot(circ)
hold off
xlim([-1.1 1.1])
ylim([-1.1 1.1])
which gives:
polyshapes.PNG
Best regards
Stephan
  4 件のコメント
John D'Errico
John D'Errico 2019 年 3 月 16 日
+1. Yes. I was going to show how to use polyshape in this, but I see that Stephan has done a good job of it.
Jullienne Franz
Jullienne Franz 2019 年 3 月 16 日
Thank you Stephan for your suggestions. I will try to incorporate your ideas in my code and hope to resolve my problem.

サインインしてコメントする。


John D'Errico
John D'Errico 2019 年 3 月 16 日
編集済み: John D'Errico 2019 年 3 月 16 日
Given two closed curves, say a circle and a square, I would first formulate the problem as a pair of functions in polar coordinates. Thus, represent these two closed curves in polar form, where we will have r as a function of theta. Once you have those relationships, the problem is absolutely trivial.
So, for a unit curcle, we have
r1 = @(theta) ones(size(theta);
For a comparable square centered at the origin, thus of side length 2, I might get trickier...
r2 = @(theta) min(1./abs(cos(theta)), 1./abs(sin(theta)));
r3 = @(theta) (r1(theta) + r2(theta))/2;
Now, all is, as I said, trivial.
theta = linspace(0,2*pi,1000);
plot(cos(theta).*r1(theta),sin(theta).*r1(theta),'b-')
hold on
plot(cos(theta).*r2(theta),sin(theta).*r2(theta),'g-')
plot(cos(theta).*r3(theta),sin(theta).*r3(theta),'r-')
axis equal
grid on
As I said, trivial.
The problem becomes considerably less trivial if you have some fully general closed curve. For example...
pxy = randn(10,2);
pxy(end+1,:) = pxy(1,:);
plot(pxy(:,1),pxy(:,2),'o-')
You cannot dispute this is a closed curve. Yet interpolation along the curve is now a bit more problematic. Thus conversion to polar coordinates is now a bit less useful. Even a simple figure 8 curve is now less automatic. So the complexity of that closed curve is important. Can it be simply represented as a single valued parametric function in polar form? If so, then all is trivial again. If not, then you need to decide how you wish to interpolate, and what is the meaning of that mean in your complex case.
Otherwise, you are doing something possibly no more meaningful than taking the average of apples and oranges, the result may be just grape juice.
  3 件のコメント
John D'Errico
John D'Errico 2019 年 3 月 16 日
Yup. That would be entirely adequate, as good as anything else. As long as they contain some point that can serve as an origin, then rotating that ray around the center is no different from what I did.
Jullienne Franz
Jullienne Franz 2019 年 3 月 16 日
Thank you John for your suggestions. I will try to work on these ideas and hope to resolve my problem.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeElementary Polygons についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by