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 visualizaciones (últimos 30 días)
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 comentarios
Aida Jones
Aida Jones el 19 de Jun. de 2018
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]);

Iniciar sesión para comentar.

Respuestas (1)

Are Mjaavatten
Are Mjaavatten el 20 de Jun. de 2018
Editada: Are Mjaavatten el 20 de Jun. de 2018
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 comentarios
Image Analyst
Image Analyst el 20 de Jun. de 2018
Try again:
Undefined function or variable 'x'.
Error in test2 (line 18)
x_circle = x + r*cos(t);
Are Mjaavatten
Are Mjaavatten el 20 de Jun. de 2018
Editada: Are Mjaavatten el 21 de Jun. de 2018
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.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by