-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotting.py
More file actions
135 lines (115 loc) · 3.71 KB
/
plotting.py
File metadata and controls
135 lines (115 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import math
import matplotlib.pyplot as plt
from panelGeometry import Point, Panel
# Methods
def plotPoints(points: list):
"""
Scatter plots a list of Points.
"""
if isinstance(points, list):
for point in points:
plt.scatter(point.x, point.y, color="k")
else:
plt.scatter(points.x, points.y)
setAxes()
def plotPanels(panels: list):
"""
Plots a list of Panels as lines.
"""
if isinstance(panels, list):
for panel in panels:
plt.plot(
[panel.startPoint.x, panel.endPoint.x],
[panel.startPoint.y, panel.endPoint.y],
color="k",
)
else:
plt.plot(
[panels.startPoint.x, panels.endPoint.x],
[panels.startPoint.y, panels.endPoint.y],
)
setAxes()
def plotBody(xVals: list, yVals: list):
"""
Plots a body by connecting xVals and yVals in order.
"""
for x, y in zip(xVals, yVals):
plt.plot(x, y)
def plotPanelsAndCps(panels: list, cps: list):
"""
Plots the panels with cp vectors at each control point.
"""
plotPanels(panels)
# plotPoints(list(panel.controlPoint for panel in panels))
for i, panel in enumerate(panels):
surfaceX = panel.controlPoint.x + 0.01 * math.cos(panel.delta)
surfaceY = panel.controlPoint.y + 0.01 * math.sin(panel.delta)
awayX = surfaceX + abs(cps[i]) * 0.1 * math.cos(panel.delta)
awayY = surfaceY + abs(cps[i]) * 0.1 * math.sin(panel.delta)
if cps[i] > 0:
plt.arrow(awayX, awayY, surfaceX - awayX, surfaceY - awayY, color="red")
else:
plt.arrow(
surfaceX, surfaceY, awayX - surfaceX, awayY - surfaceY, color="blue"
)
def plotCircle(radius: float, firstPoint: Point):
"""
Plots a circle given a radius and the first point.
"""
circle = plt.Circle(
(firstPoint.x + radius, firstPoint.y + radius), radius, fill=False, color="k"
)
axes = plt.gca()
axes.add_patch(circle)
def plotCps(points: list, cps: list, color="blue", label=""):
"""
Scatter plots c_p vs x/c given the points and cps in order.
"""
maxX = max(point.x for point in points)
minX = min(point.x for point in points)
chordLength = maxX - minX
first = True
for point, cp in zip(points, cps):
if first:
plt.plot([(point.x / chordLength)], [cp], "o", color=color, label=label, markersize=3)
first = False
else:
plt.plot([(point.x / chordLength)], [cp], "o", color=color, markersize=3)
plt.xlabel("$x/c$")
plt.ylabel("$c_p$")
plt.gca().invert_yaxis()
def plotCpsForCircle(panels: list, cps: list):
"""
Scatter plots c_p vs theta given the panels and cps in order.
"""
for panel, cp in zip(panels, cps):
plt.plot([math.degrees(panel.delta)], [cp], "o", color="blue")
plt.xlabel("$\Theta$")
plt.ylabel("$c_p$")
def plotCircleAnalyticalCps(resolution: int):
"""
Plots the curve for the solution cp=1-4sin^2(theta) of a given resolution.
"""
cps = []
thetas = []
xs = range(1, resolution)
step = resolution / (2 * math.pi)
xs = [theta / step for theta in xs]
for theta in xs:
thetas.append(math.degrees(theta))
cp = 1 - 4 * (math.sin(theta)) ** 2
cps.append(cp)
plt.plot(thetas, cps)
def plotAlphaAndCls(alphas: list, cps: list):
"""
Scatter plots c_l vs alpha given the angles and cps in order.
"""
plt.scatter(alphas, cps, label="Calculated")
plt.xlabel(r"$\alpha$")
plt.ylabel("$c_l$")
def setAxes():
"""
Sets the aspect ratio of the axes to 1.
"""
axes = plt.gca()
axes.set_aspect(1)