필터 지우기
필터 지우기

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?

조회 수: 2 (최근 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
Aida Jones
Aida Jones 2018년 6월 19일
I have tried another one. Plz check this and correct this one to find the centroid of the sectored circle.: x=[3]; y=[3]; r=[2]; delta=pi/2; theta=2*pi; theta2 = theta + delta/2; t = linspace(theta,theta2); A = x + r*cos(t); B = y + r*sin(t); xV=x + ((2*r/3)*cos(theta2)*sin(delta/2)/(delta/2));%EDA II yV=y + ((2*r/3)*sin(theta2)*sin(delta/2)/(delta/2));%EDA II plot([x,A,x],[y,B,y],'b-',xV,yV,'ro') axis([0 10 0 10]);

댓글을 달려면 로그인하십시오.

답변 (1개)

Are Mjaavatten
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
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
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 CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by