MATLAB: Centroid of an airfoil

clc;clear all;close all
%I separated the data points of the top and the bottom of the airfoil so I
%can use interp1 separately for both
%Data points of the top part of the airfoil
x=[1 0.8518 0.7040 0.5536 0.3988 0.2454 0.0937 0.0199 0.0015 0];
y=[0 0.0355 0.0819 0.1206 0.1347 0.1200 0.0777 0.0363 0.0162 0];
%Data points of the bottom part of the airfoil
x2=[0 0.0169 0.0812 0.2054 0.3525 0.4979 0.6457 0.7974 0.9497 1];
y2=[0 -0.0197 -0.0428 -0.0645 -0.0749 -0.0701 -0.0506 -0.0249 -0.0026 0];
%Smoothing both the top and bottom part of the airfoil using
%interp1('pchip')
xx=linspace(1,0);
yy=interp1(x,y,xx,'pchip');
xx2=linspace(0,1);
yy2=interp1(x2,y2,xx2,'pchip');
%Plotting both my smoothed top and bottom data points into the same plot
figure
plot(xx,yy,'b',xx2,yy2,'b')
grid on
This is what I have come up with so far. How do I find the centroid of this airfoil

Best Answer

If you have the image processing toolbox, you can use the xx, yy, xx2, yy2 coordinates as inputs to poly2mask(). Then you can use regionprops() to find the centroid of the mask.