Interpolate value between arc

Note that now I have this function to create my arc
a=[1 1]; %P1
b=[9 9]; %P2
r=10; %radius
syms x y
[x,y]=solve((x-a(1))^2+(y-a(2))^2==r^2,(x-b(1))^2+(y-b(2))^2==r^2,x,y);
syms X Y
ezplot((X-x(1))^2+(Y-y(1))^2==r^2,[min(a(1),b(1)),max(a(1),b(1)), ...
min(a(2),b(2)),max(a(2),b(2))])
axis equal
ezplot((X-x(2))^2+(Y-y(2))^2==r^2,[min(a(1),b(1)),max(a(1),b(1)), ...
min(a(2),b(2)),max(a(2),b(2))])
axis equal
After plotting the arc, I need to know the points lie between the arc with random interpolate points n
How to do this?

3 件のコメント

Roger Stafford
Roger Stafford 2017 年 11 月 19 日
Question: What do you mean exactly by "the points lie between the arc". What points are you talking about and what does it mean "between" - between what?
TS Low
TS Low 2017 年 11 月 19 日
編集済み: TS Low 2017 年 11 月 19 日
ok, i think u comment on my previous post too
the points lie between point A and B
In this case, which is (1,1) and (9,9)
Now i am going to give matlab interpolate number of 7 (example)
Then, the result i want should be
(1.788,2.566)
(2.566,2.888)
(...)
(...)
(...)
(...)
(8.777,8.888)
*[Just example, not true value]
Walter Roberson
Walter Roberson 2017 年 11 月 19 日
Those ezplot need to be changed to fimplicit

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

回答 (3 件)

Walter Roberson
Walter Roberson 2017 年 11 月 19 日

0 投票

The equation you are using is a circle centered at x(1), y(1) with radius r. You know the endpoints; you can convert them into polar coordinates relative to the center. Now use linspace(first_theta, second_theta, 10) as the angle and r as the radius and put that through pol2cart, add x(1), y(1) to get the cartesian coordinates of the points of interest.

9 件のコメント

TS Low
TS Low 2017 年 11 月 19 日
So i need to change ezplot to fimplicit and also change my point and radius equation?
Walter Roberson
Walter Roberson 2017 年 11 月 19 日
You need to change ezplot to fimplicit. You do not need to change your point and radius equation: it just is not of benefit to you to use them directly to calculate the intermediate locations.
[TH, R] = cart2pol([endpoint1_x - x(1), endpoint2_x - x(1)], [endpoint1_y - y(1), endpoint2_y - y(1)]);
TH10 = linspace(TH(1), TH(2), 10);
[X10, Y10] = pol2cart(TH10, r);
X10 = X10 + x(1);
Y10 = Y10 + y(1);
TS Low
TS Low 2017 年 11 月 20 日
ok thx, i will try on the suggestion u give me
Walter Roberson
Walter Roberson 2017 年 11 月 21 日
%first input
% a=[1 1];
%P1
% b=[9 9];
%P2
A(1) = input('Please type your x1: ');
B(1) = input('Please type your y1: ');
A(2) = input('Please type your x2: ');
B(2) = input('Please type your y2: ');
a = [A(1) B(1)];
b = [A(2) B(2)];
r = input('Please type your radius: ');
%next solution
syms x y
[xsol, ysol]=solve((x-a(1))^2+(y-a(2))^2==r^2,(x-b(1))^2+(y-b(2))^2==r^2,x,y);
%plot arc
syms X Y
figure(1)
fimplicit((X-xsol(1))^2+(Y-ysol(1))^2==r^2,[min(a(1),b(1)),max(a(1),b(1)), ...
min(a(2),b(2)),max(a(2),b(2))])
axis equal
figure(2)
fimplicit((X-xsol(2))^2+(Y-ysol(2))^2==r^2,[min(a(1),b(1)),max(a(1),b(1)), ...
min(a(2),b(2)),max(a(2),b(2))])
axis equal
[TH, R] = cart2pol([a(1) - xsol(1), b(1) - xsol(1)], [a(2) - ysol(1), b(2) - ysol(1)]);
TH10 = linspace(TH(1), TH(2), 10);
[X10, Y10] = pol2cart(TH10, r);
X10 = X10 + xsol(1);
Y10 = Y10 + ysol(1);
figure(1)
hold on
plot(X10, Y10, 'rx');
hold off
TS Low
TS Low 2017 年 11 月 21 日
I try to solve it Now the figure one no longer shown and the fimplicit can't be use which i try before
Walter Roberson
Walter Roberson 2017 年 11 月 21 日
Which MATLAB release are you using? That code needs R2016b or later in order to use fimplicit()
TS Low
TS Low 2017 年 11 月 22 日
i m using 2016a? So now the problem is the version? Any other alternative way to solve this?
Walter Roberson
Walter Roberson 2017 年 11 月 22 日
Ah... I just tried again and this time ezplot worked, at least in R2017b. You could try changing to ezplot()
TS Low
TS Low 2017 年 11 月 26 日

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

Roger Stafford
Roger Stafford 2017 年 11 月 19 日
編集済み: Walter Roberson 2017 年 11 月 19 日

0 投票

I contend the right way to do that task is to calculate the center of the circular arc you have defined, and then generate the plotted arc using a varying angle that swings from the first point to the second point. You can carry out the desired interpolations in terms of values of this arc angle using 'interp1'.
You might be interested in the following "Answers" contribution:
(which I think was asked by you, TS Low.)

1 件のコメント

Roger Stafford
Roger Stafford 2017 年 11 月 19 日
You should not expect the contributors who answer questions to do all your work for you. It should be sufficient to indicate the solution to difficulties you are facing. You should fill in the rest of the details yourself. Otherwise, how are you going to learn Matlab programming?

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

Image Analyst
Image Analyst 2017 年 11 月 19 日

0 投票

Try spline(). See my attached demo.

3 件のコメント

TS Low
TS Low 2017 年 11 月 19 日
yes sir
i no need spline
I given user start point, end point, and radius
thus i need to create a curve and knowing the points that pass thru
Image Analyst
Image Analyst 2017 年 11 月 19 日
Of course you could use spline, but actually I think Walter's linspace idea is much simpler.
TS Low
TS Low 2017 年 11 月 20 日
thx bro

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

カテゴリ

質問済み:

2017 年 11 月 19 日

コメント済み:

2017 年 11 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by