Created
May 30, 2019 11:46
-
-
Save mkeeter/355a269fd0c4c5ff82c3f413159b547c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sage code to generate NACA airfoil equations | |
import operator | |
var('x, y, xc, m, p') | |
def run(y_chord): | |
g_chord = vector([1, derivative(y_chord(xc), xc)]) | |
pos_pt = vector([x, y]) | |
pos_chord = vector([xc, y_chord(xc)]) | |
delta = pos_pt - pos_chord | |
print delta.dot_product(g_chord) == 0 | |
sols = solve(delta.dot_product(g_chord) == 0, xc) | |
return expand(sols[1].op[1]) | |
def to_prefix(expr): | |
if expr.operator() == None: | |
if str(expr) == 'I': | |
return '0' | |
return str(expr) | |
children = " ".join(map(to_prefix, expr.op)) | |
f = {operator.add: "+", | |
operator.sub: "-", | |
operator.pow: "expt", | |
operator.mul: "*"}[expr.operator()] | |
return "(%s %s)" % (f, children) | |
def to_func(y_chord): | |
return """ (define (yc x) | |
%s) | |
(define (xc x y) | |
%s) | |
(lambda (x y) | |
(let ((x (xc x y))) | |
(values x (yc x))))""" % (to_prefix(y_chord(x)), | |
to_prefix(run(y_chord))) | |
y_chord_a = lambda x: m * (2*x/p -(x/p)^2) | |
y_chord_b = lambda x: m / (1-p)^2 * (1-2*p + 2*p*x - x^2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment