# [Scripting]: How to get the coordinates of a 2D airfoil @ different angles of attack?

 Register Blogs Members List Search Today's Posts Mark Forums Read

November 25, 2017, 00:37
[Scripting]: How to get the coordinates of a 2D airfoil @ different angles of attack?
#1
New Member

Join Date: Oct 2017
Posts: 15
Rep Power: 7
I have this piece of code which calculates the coordinates of a point(qx,qy) after it is rotated around an origin(ox, oy) by an angle(angle):
Code:
```import math

def rotate(origin, point, angle):

ox, oy = origin
px, py = point

qx = ox + math.cos(angle) * (px - ox) - math.sin(angle) * (py - oy)
qy = oy + math.sin(angle) * (px - ox) + math.cos(angle) * (py - oy)

return qx, qy

I want to get the coordinates of an airfoil at different angle of attacks. For this, I want the final script to be able to read the x,y coordinates of the airfoil at 0 degrees angle of attack from a .txt file, do the calculation for all the coordinates for a new angle of attack and then export the results to a new .geo file.

I have this code that lets the script to open the .txt file with the coordinates at 0 angle of attack:

Code:
```coordsAt0 = []
with open('coordinatesAt0.txt') as fin:

for l in fin:

coords = map(float,l.split())

coordsAt0.append(coords[:2])```
After the calculation of the coordinates for the new angle of attack, I have this code which exports the new coordinates to a new .geo file.

Quote:
 with open('newcoordinates.geo','w') as fout: for i, c in enumerate(coordsAt0): fout.write('Point (%i) = {%f, %f, 0, 1};\n'%(i+1,c[0],c[1]))
My problem is how should I implement the code that calculates the new coordinates of the airfoil at a new angle of attack?

Any hint or a simpler piece of code on how to do it would be greatly appreciated!

Regards,
CfdIntro

 November 26, 2017, 14:43 #2 Senior Member   Mikko Join Date: Jul 2014 Location: The Hague, The Netherlands Posts: 243 Rep Power: 11 Hi, Looks like a familiar piece of code :-) After line Code: `coords = map(float,l.split())` You can just add the rotate function call Code: ```angle = 10 # degrees origin = (0,0) coords0 = rotate(coords[:2], origin, math.radians(angle)) coordsAt0.append(coords0)``` Regards, Mikko lcarasik and CfdIntro like this.

December 12, 2017, 10:23
#3
New Member

Join Date: Oct 2017
Posts: 15
Rep Power: 7
Quote:
 Originally Posted by Flowkersma Hi, Looks like a familiar piece of code :-) After line Code: `coords = map(float,l.split())` You can just add the rotate function call Code: ```angle = 10 # degrees origin = (0,0) coords0 = rotate(coords[:2], origin, math.radians(angle)) coordsAt0.append(coords0)``` Regards, Mikko
Hi,

I was trying to have the script open the .txt file with the coordinates at 0 AoA, rotate the coordinates by the desired AoA, print the results into a new .txt file, then read the coordinates at the new AoA and finally export the results into a .geo format file. That being said, your suggestion saved me about 30 lines of code!

Thanks again for the tip

Regards,
CfdIntro

 Tags airfoil 2d, angle of attack, coordinates from .txt, python script