I need help with a script that involves manipulating .dat files, that contains airfoil points. The airfoil data is received in column forms containing the x,y coordinates of the point in normalized form, with a 1m chord. I would like to make a script that returns the airfoil points in a .dat file in which I:
Multiply each point by the desired chord value (Since the points are normalized to 1m, each point must be multiplied by a chosen string value in order to scale the airfoil);
Rotate these points to a given angle of attack, described in degrees. In the script below is my idea of how to describe this rotation for the application I want to realize;
Move the points so that the origin (0,0) becomes the center of pressure of the airfoil (so for each point x,y, a math addition will be made to move the origin to the center of pressure).
The airfoil .dat file, chord value, angle of attack, and translation are inputs to be put into the code. My question is how to interpret the .dat file and generate another .dat file as output with the data modified by the math operations listed above.
Attached is a .dat file of the airfoil and the math operations to implement in the script
airfoil NACA2414.dat from AirfoilTools
def scale(self):
xs = []
ys = []
for point in self.data:
x, y = point
xs.append(float(x)*self.chord)
ys.append(float(y)*self.chord)
self.data = tuple(zip(xs, ys))
return self.data
def rotate(self):
ox, oy = (0, 0)
xs = []
ys = []
for point in self.data:
x, y = point
xs.append(ox + math.cos(math.radians(-self.alpha)) * (float(x) - ox) - math.sin(math.radians(-self.alpha)) * (float(y) - oy))
ys.append(oy + math.sin(math.radians(-self.alpha)) * (float(x) - ox) + math.cos(math.radians(-self.alpha)) * (float(y) - oy))
self.data = tuple(zip(zs, ys))
return self.data
def translate(self):
xs = []
ys = []
for point in self.data:
x, y = point
xs.append(float(x) + self.x_trans)
ys.append(float(y) + self.y_trans)
self.data = tuple(zip(xs, ys))
return self.data