MATLAB: How to move points in a curve in the normal direction

curve modificationgeometry manipulationgeometry perturbationMATLABnormaltangent

I am trying to make an airfoil 2D cross section larger or smaller wihout editing the shape of the profile. I figured that the best way to do this would be to determine a vector normal to each point and then add each point's normal vector x and y coordinates to it's original coordinates, scaling appropriately for the level of modification I require. In the absence of a function defining the curve, what is the best mthod to find tangents/normals?
I have used the code below to determine what I think are the tangent vectors at each point and then converted these tangents to normals, however when I plot the normals it is not giving me the results I desire.
clear all;
clc;
% Read Airfoil coordinate file
coord_file=dlmread('S2_R3_rotated.txt');
% Extract x & y columns as variables
x_airfoil=coord_file(:,1);
y_airfoil=coord_file(:,2);
% Define tolerance
tol = 0.003;
% Determine tangent and normal vectors to perturb profile
close
figure(1); hold on
for i=1:length(x_airfoil)-1
x_t(1, 1) = x_airfoil(i, 1);
y_t(1, 1) = y_airfoil(i, 1);
x_t(2, 1) = x_airfoil(i, 1) + tol*(x_airfoil(i+1, 1)-x_airfoil(i, 1))/sqrt(((x_airfoil(i+1, 1)-x_airfoil(i, 1))^2+(y_airfoil(i+1, 1)-y_airfoil(i, 1))^2));
y_t(2, 1) = y_airfoil(i, 1) + tol*(y_airfoil(i+1, 1)-y_airfoil(i, 1))/sqrt(((x_airfoil(i+1, 1)-x_airfoil(i, 1))^2+(y_airfoil(i+1, 1)-y_airfoil(i, 1))^2));
x_n(1, 1) = x_airfoil(i, 1);
y_n(1, 1) = y_airfoil(i, 1);
x_n(2, 1) = x_airfoil(i, 1) + -1*tol*(y_airfoil(i+1, 1)-y_airfoil(i, 1))/sqrt(((x_airfoil(i+1, 1)-x_airfoil(i, 1))^2+(y_airfoil(i+1, 1)-y_airfoil(i, 1))^2));
y_n(2, 1) = y_airfoil(i, 1) + -1*tol*(x_airfoil(i+1, 1)-x_airfoil(i, 1))/sqrt(((x_airfoil(i+1, 1)-x_airfoil(i, 1))^2+(y_airfoil(i+1, 1)-y_airfoil(i, 1))^2));
x_perturbed(i, 1) = x_n(2,1);
y_perturbed(i, 1) = y_n(2,1);
end
plot(x_airfoil, y_airfoil, 'b', x_perturbed, y_perturbed, 'r');
grid on;
xlabel('X Coordinate');
ylabel('Y Coordinate');
legend('Original Airfoil Profile', 'Pertubed airfoil profile');
title('Stage 2 Blade- Radius 3');
hold off
When I plot the coordinates, this is what I get:
Capture.PNG
This is very close to what I am aiming for however I am confused about why the profiles cross over at either side.
All help appreciated, thanks.

Best Answer

Try to reverse the sign before tol
x_n(2, 1) = x_airfoil(i, 1) + +1*tol*(y_airfoil(i+1, 1)-y_airfoil(i, 1))/sqrt(((x_airfoil(i+1, 1)-x_airfoil(i, 1))^2+(y_airfoil(i+1, 1)-y_airfoil(i, 1))^2));
y_n(2, 1) = y_airfoil(i, 1) + -1*tol*(x_airfoil(i+1, 1)-x_airfoil(i, 1))/sqrt(((x_airfoil(i+1, 1)-x_airfoil(i, 1))^2+(y_airfoil(i+1, 1)-y_airfoil(i, 1))^2));
Or the opposite
x_n(2, 1) = x_airfoil(i, 1) + -1*tol*(y_airfoil(i+1, 1)-y_airfoil(i, 1))/sqrt(((x_airfoil(i+1, 1)-x_airfoil(i, 1))^2+(y_airfoil(i+1, 1)-y_airfoil(i, 1))^2));
y_n(2, 1) = y_airfoil(i, 1) + +1*tol*(x_airfoil(i+1, 1)-x_airfoil(i, 1))/sqrt(((x_airfoil(i+1, 1)-x_airfoil(i, 1))^2+(y_airfoil(i+1, 1)-y_airfoil(i, 1))^2));