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 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Are Mjaavatten
am 20 Jun. 2018
Bearbeitet: Are Mjaavatten
am 20 Jun. 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 Kommentare
Image Analyst
am 20 Jun. 2018
Try again:
Undefined function or variable 'x'.
Error in test2 (line 18)
x_circle = x + r*cos(t);
Are Mjaavatten
am 20 Jun. 2018
Bearbeitet: Are Mjaavatten
am 21 Jun. 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.
Siehe auch
Kategorien
Mehr zu Detection finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!