# [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,c))
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: 12 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 Thread Tools Search this Thread Show Printable Version Email this Page Search this Thread: Advanced Search Display Modes Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are Off Pingbacks are On Refbacks are On Forum Rules Similar Threads Thread Thread Starter Forum Replies Last Post feiyi SU2 4 September 30, 2019 12:42 Ry10 SU2 15 October 30, 2016 17:27 RLangtry SU2 2 August 5, 2014 09:48 Hybrid ANSYS 3 May 10, 2012 22:26 Yasser Nabavi FLUENT 0 April 21, 2006 17:28

All times are GMT -4. The time now is 08:03.