How to determine the centroid of this fan(triangle) where the coordinates of one of the vertices is only known and the distance is also known?
3 ビュー (過去 30 日間)
古いコメントを表示
I am not getting the centroid correctly. Please check the code.
x=[3];
y=[3];
r=[2];
delta=pi/3;
theta=2*pi*0.4;
si=size(x);
for i=1:si(2)
theta2 = theta + delta;
t = linspace(theta,theta2);
A = x(i) + r(i)*cos(t);
B = y(i) + r(i)*sin(t);
x_cen = mean(A)
y_cen = mean(B)
plot([x(i),A,x(i)],[y(i),B,y(i)],'b-',x_cen,y_cen,'ro')
axis([0 10 0 10]);
end
4 件のコメント
回答 (1 件)
Are Mjaavatten
2018 年 6 月 20 日
編集済み: Are Mjaavatten
2018 年 6 月 20 日
In my comment there was a typo in the expression for the centroid. A factor of 1/3 was missing. Sorry about that.
Here is a script that should give you what you want:
clear;
% Circle:
x_center= 3;
y_center= 3;
r = 2;
% Sector:
delta=pi/3; % Sector width
theta=2*pi*0.4; % Sector start angle
alpha = theta+ delta/2; % Sector center line angle
r_centroid = 4*r*sin(delta/2)/delta/3;
% Translate and rotate:
x_centroid = x_center + r_centroid*cos(alpha);
y_centroid = y_center + r_centroid*sin(alpha);
figure(1);
% Plot full circle:
t = linspace(0,2*pi);
x_circle = x_center + r*cos(t);
y_circle = y_center + r*sin(t);
plot(x_circle,y_circle,'--b',x_center,y_center,'*k');
hold on
% Plot sector:
t = linspace(theta,theta+delta);
A = x_center + r*cos(t);
B = y_center + r*sin(t);
plot([x_center,A,x_center],[y_center,B,y_center],'b-', ...
x_centroid,y_centroid,'ro')
axis([0 6 0 6]);
axis equal
hold off
2 件のコメント
Image Analyst
2018 年 6 月 20 日
Try again:
Undefined function or variable 'x'.
Error in test2 (line 18)
x_circle = x + r*cos(t);
Are Mjaavatten
2018 年 6 月 20 日
編集済み: Are Mjaavatten
2018 年 6 月 21 日
At some point i changed the variable name from x to x_center, but forgot to change all occurrences. I should have learned by now to start a script with clear, to avoid goofs like this.
I have also corrected an error in the expression for r_centroid, where I had mixed up the full and the half sector angle. The script should be correct now.
参考
カテゴリ
Help Center および File Exchange で Detection についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!