How to find angle between a fixed point to multiple point ??
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I would like to calculate the angle ABC which is shown in the figure. I have fixed line AB and multiple point on the boundary-1 (in red colour). I want to calculate a array of angle between line AB and BC (C is a moving point is on the boundary-1) and also corresponding distance from point C to nearest point on the boundary-2(in green colour). I attached a figure for clearification and boundaries mat file.
Thank you for your help
採用された回答
Perhaps this —
M = load('M.mat');
M = M.M;
N = load('N.mat');
N = N.N;
xv = 506; % Determined Manually
yv = 119; % Determined Manually
a = atan2d(M(:,2)-yv, M(:,1)-xv); % Angles (°)
d = hypot(yv-M(:,2), xv-M(:,1)); % Distances
v = (1:210:size(M,1)).'; % Selection Vector For Plot
figure
plot(N(:,1), N(:,2),'g')
hold on
plot(M(:,1), M(:,2),'r')
plot([xv*ones(size(v)) M(v,1)].', [yv*ones(size(v)) M(v,2)].', '--m')
plot(506, 119,'k+')
yl = ylim;
plot([1 1]*506, [yl(1) 119], '-k')
hold off
grid
Ax = gca;
% Ax.YDir = 'reverse';
axis('equal')
text(M(v,1), M(v,2), compose('\\leftarrow r = %.2f, \\theta = %.2f\\circ', [d(v) a(v)]), 'Rotation',0)

The angles make more sense with a normal y-axis direction. Un-comment the ‘YDir’ assignment to show it as in the original image.
.
6 件のコメント
Thank you for your reply. It is also worked well for my case. But I have some other measurement. I attached a image (Which is the cropped image). In this image, C is the moving point(indicated by black circle) and supposed E is the point normal to line BC which lies on the boundary-2. The distance between point E and C is the d (which is indicated in the image). Can you give provide the any solution to calculate the distance d??
Again thank you for your contribution.
This was interesting!
There are 1367 data pairs in ‘M’ and 3266 in ‘N’ and the approsimate coordinating pairs do not strictly coincide. Since any sort of direct comparison is not likely to be efficient because of that, I decided to use hypot again, this time searching for the minimum distance between the ‘M’ coordinates (looping on them) and the ‘N’ coordinates, returning that distance and the associated index. of the matching ‘N’ pair. This sort of ‘exhaustive search’ is generally not efficient, however it works here because of the way the data are arranged.
That approach seems to have worked —
M = load('M.mat');
M = M.M;
N = load('N.mat');
N = N.N;
xv = 506; % Determined Manually
yv = 119; % Determined Manually
a = atan2d(M(:,2)-yv, M(:,1)-xv); % Angles (°)
d = hypot(yv-M(:,2), xv-M(:,1)); % Distances
v = (1:210:size(M,1)).'; % Selection Vector For Plot
figure
plot(N(:,1), N(:,2),'g')
hold on
plot(M(:,1), M(:,2),'r')
plot([xv*ones(size(v)) M(v,1)].', [yv*ones(size(v)) M(v,2)].', '--m')
plot(506, 119,'k+')
yl = ylim;
plot([1 1]*506, [yl(1) 119], '-k')
hold off
grid
Ax = gca;
% Ax.YDir = 'reverse';
axis('equal')
text(M(v,1), M(v,2), compose('\\leftarrow r = %.2f, \\theta = %.2f\\circ', [d(v) a(v)]), 'Rotation',0)

for k = 1:size(M,1)
[dh,ix] = min(hypot(M(k,2)-N(:,2), M(k,1)-N(:,1)));
dv(k,:) = dh;
ixv(k,:) = ix;
end
dist_table = table(dv, ixv, M, N(ixv,:), 'VariableNames',{'Distance','M(index)','M','N(M(index),:)'})
dist_table = 1367×4 table
Distance M(index) M N(M(index),:)
________ ________ __________ _____________
58.464 3239 507 133 520 76
58.189 3232 508 133 527 78
58.822 3232 509 134 527 78
57.567 3232 510 133 527 78
57.245 3229 511 133 530 79
55.973 3229 512 132 530 79
55.66 3229 513 132 530 79
55.362 3226 514 132 533 80
55.027 3226 515 132 533 80
53.759 3226 516 131 533 80
52.811 3226 516 130 533 80
52.498 3226 517 130 533 80
51.245 3226 518 129 533 80
49.98 3223 519 128 536 81
48.703 3223 520 127 536 81
47.76 3223 520 126 536 81
select = M(:,1)>369 & M(:,1)<386 & M(:,2)>250 & M(:,2)<350;
dist_table_matching_detail_plot = dist_table(select,:)
dist_table_matching_detail_plot = 99×4 table
Distance M(index) M N(M(index),:)
________ ________ __________ _____________
5.831 406 385 349 380 352
6 402 385 348 379 348
6.0828 402 385 347 379 348
6.3246 402 385 346 379 348
5.831 402 384 345 379 348
6.0828 399 384 344 378 345
6.3246 399 384 343 378 345
6.7082 399 384 342 378 345
6 395 383 341 377 341
6.0828 395 383 340 377 341
6.3246 395 383 339 377 341
6.7082 395 383 338 377 341
7 391 383 337 376 337
7 390 383 336 376 336
6 389 382 335 376 335
6.0828 389 382 334 376 335
figure
plot(N(ixv,1), N(ixv,2),'.g')
hold on
plot(M(:,1), M(:,2),'.r')
plot([M(:,1) N(ixv,1)].', [M(:,2) N(ixv,2)].','k')
hold off
axis equal
grid
axis([369 386 250 350])
xlabel('X [M(:,1), N(:,1)]')
ylabel('Y [M(:,2), N(:,2)]')
title('Enlarged Section (Detail)')

The distance appear to be appropriate with respect to the plot. Sinc the earlier distances and radii are from the central reference to the red ‘M’ curve, the earlier distances can be indexed to the distances between the curves.
Distance_Angle_Summary = table(M, d, a, dv, 'VariableNames',{'M','Reference Distance','Reference Angle(°)','Radial Distance (M-N)'})
Distance_Angle_Summary = 1367×4 table
M Reference Distance Reference Angle(°) Radial Distance (M-N)
__________ __________________ __________________ _____________________
507 133 14.036 85.914 58.464
508 133 14.142 81.87 58.189
509 134 15.297 78.69 58.822
510 133 14.56 74.055 57.567
511 133 14.866 70.346 57.245
512 132 14.318 65.225 55.973
513 132 14.765 61.699 55.66
514 132 15.264 58.392 55.362
515 132 15.811 55.305 55.027
516 131 15.62 50.194 53.759
516 130 14.866 47.726 52.811
517 130 15.556 45 52.498
518 129 15.62 39.806 51.245
519 128 15.811 34.695 49.98
520 127 16.125 29.745 48.703
520 126 15.652 26.565 47.76
If you want to compute the angle of the radial distances (distances between the two curves), that would be simply:
av = atan2d(M(:,2)-N(ixv,2), M(k,1)-N(ixv,1));
I checked that, and specifically on the ‘select’ subset. It works.
.
Thank you for your help. It works for me. Can you tell me how will i seperate the extruded part from the boundary-2 (which is shows in the image matlab.png in green circle). I want to seperate the green circle portion from the green line (boundary-2). I also mention the extruded part in the attached figure). Can you give me some hint on it ??
Thank you for time.
This is a challenging project. (There might be a more efficient way to do this with image processing functions, however none of the ones I looked at aeemed to provide a solution to this.)
Th code works by first creating a polyshape from the ‘N’ coordinates (this considerably reduces the number of data points), then calculates the centroid coordinates of the polyshape and uses hypot and atan2 to generate the radii (‘r’) and angles (‘th’) from it to the rest of the polyshape. The angles (‘th’) are made consistent and increasing using the unwrap function, creating ‘uth’. After some editing to get rid of unnecessary data (with ‘qix’), it then creates a vector of srtictly increasing angles in ‘uthq’ and then interpolates them to create ‘rq’. This creates the desired result that can be further used to process to remove the extrusions, done with the movmin to essentially ‘filter out’ the extrusions. That result is plotted as the magneta lline in the figure.
M = load('M.mat');
M = M.M;
N = load('N.mat');
N = N.N;
pgn = polyshape(N(:,1), N(:,2), 'Simplify',1, 'KeepCollinearPoints',0);
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
[cx,cy] = centroid(pgn);
vtcs = pgn.Vertices;
vx = pgn.Vertices(:,1);
vy = pgn.Vertices(:,2);
th = atan2(vy-cy, vx-cx);
r = hypot(vy-cy, vx-cx);
uth = unwrap(th);
ixv = 1:numel(r);
uth = uth(~isnan(uth));
qix = find(diff([uth(1); uth])<-2,1,'first');
uthidx = 1:qix-1;
uth = uth(uthidx);
r = r(uthidx);
uthq = linspace(min(uth), max(uth), numel(uth));
rq = interp1(uth, r, uthq);
rqmin = movmin(rq, 29);
% figure
% plot(uth,r)
% hold on
% plot(uthq, rqmin)
% hold off
% grid
xs = r.*cos(uth)+cx;
ys = r.*sin(uth)+cy;
xsq = rqmin.*cos(uthq)+cx;
ysq = rqmin.*sin(uthq)+cy;
figure
plot(xs,ys)
hold on
plot(xsq, ysq, '-m')
hold off
grid
axis('equal')

I cannot claim that this is robust to even similar data sets. It seems to work reasonably well here.
.
ok thank you for your help
As always, my pleasure!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
