Skip to content

Commit 7e4d180

Browse files
committed
enh: add draw() methods
1 parent d898773 commit 7e4d180

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed

rocketpy/AeroSurfaces.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,96 @@ def evaluateCenterOfPressure(self):
339339
self.cp = (self.cpx, self.cpy, self.cpz)
340340
return self.cp
341341

342+
def draw(self):
343+
# Color cycle [#348ABD, #A60628, #7A68A6, #467821, #D55E00, #CC79A7, #56B4E9, #009E73, #F0E442, #0072B2]
344+
# Fin
345+
leadingEdge = plt.Line2D((0, self.sweepLength), (0, self.span), color="#A60628")
346+
tip = plt.Line2D(
347+
(self.sweepLength, self.sweepLength + self.tipChord),
348+
(self.span, self.span),
349+
color="#A60628",
350+
)
351+
backEdge = plt.Line2D(
352+
(self.sweepLength + self.tipChord, self.rootChord),
353+
(self.span, 0),
354+
color="#A60628",
355+
)
356+
root = plt.Line2D((self.rootChord, 0), (0, 0), color="#A60628")
357+
358+
# Center and Quarter line
359+
center_line = plt.Line2D(
360+
(self.rootChord / 2, self.sweepLength + self.tipChord / 2),
361+
(0, self.span),
362+
color="#7A68A6",
363+
alpha=0.35,
364+
linestyle="--",
365+
label="Center Line",
366+
)
367+
quarter_line = plt.Line2D(
368+
(self.rootChord / 4, self.sweepLength + self.tipChord / 4),
369+
(0, self.span),
370+
color="#7A68A6",
371+
alpha=1,
372+
linestyle="--",
373+
label="Quarter Line",
374+
)
375+
376+
# Center of pressure
377+
cp_point = [abs(self.distanceToCM - self.cpz), self.Yma]
378+
379+
# Mean Aerodynamic Chord
380+
Yma_start = (
381+
self.sweepLength
382+
* (self.rootChord + 2 * self.tipChord)
383+
/ (3 * (self.rootChord + self.tipChord))
384+
)
385+
Yma_end = (
386+
2 * self.rootChord**2
387+
+ self.rootChord * self.sweepLength
388+
+ 2 * self.rootChord * self.tipChord
389+
+ 2 * self.sweepLength * self.tipChord
390+
+ 2 * self.tipChord**2
391+
) / (3 * (self.rootChord + self.tipChord))
392+
Yma_line = plt.Line2D(
393+
(Yma_start, Yma_end),
394+
(self.Yma, self.Yma),
395+
color="#467821",
396+
linestyle="--",
397+
label="Mean Aerodynamic Chord",
398+
)
399+
400+
# Plotting
401+
fig3 = plt.figure(figsize=(4, 4))
402+
with plt.style.context("bmh"):
403+
ax1 = fig3.add_subplot(111)
404+
405+
# Fin
406+
ax1.add_line(leadingEdge)
407+
ax1.add_line(tip)
408+
ax1.add_line(backEdge)
409+
ax1.add_line(root)
410+
411+
ax1.add_line(center_line)
412+
ax1.add_line(quarter_line)
413+
ax1.add_line(Yma_line)
414+
ax1.scatter(
415+
*cp_point, label="Center Of Pressure", color="red", s=100, zorder=10
416+
)
417+
ax1.scatter(*cp_point, facecolors="none", edgecolors="red", s=500, zorder=10)
418+
419+
# Plot settings
420+
xlim = (
421+
self.rootChord
422+
if self.sweepLength + self.tipChord < self.rootChord
423+
else self.sweepLength + self.tipChord
424+
)
425+
ax1.set_xlim(0, xlim * 1.1)
426+
ax1.set_ylim(0, self.span * 1.1)
427+
ax1.set_xlabel("Root Chord")
428+
ax1.set_ylabel("Span")
429+
ax1.set_title("Trapezoidal Fin")
430+
ax1.legend(bbox_to_anchor=(1.05, 1.0), loc="upper left")
431+
342432

343433
class EllipticalFins(Fins):
344434
def __init__(
@@ -447,6 +537,64 @@ def evaluateCenterOfPressure(self):
447537
self.cp = (self.cpx, self.cpy, self.cpz)
448538
return self
449539

540+
def draw(self):
541+
# Color cycle [#348ABD, #A60628, #7A68A6, #467821, #D55E00, #CC79A7, #56B4E9, #009E73, #F0E442, #0072B2]
542+
# Ellipse
543+
el = Ellipse(
544+
(self.rootChord / 2, 0),
545+
self.rootChord,
546+
self.span * 2,
547+
fill=False,
548+
edgecolor="#A60628",
549+
linewidth=2,
550+
)
551+
552+
# Mean Aerodynamic Chord
553+
Yma_length = 8 * self.rootChord / (3 * np.pi) # From barrowman
554+
Yma_start = (self.rootChord - Yma_length) / 2
555+
Yma_end = self.rootChord - (self.rootChord - Yma_length) / 2
556+
Yma_line = plt.Line2D(
557+
(Yma_start, Yma_end),
558+
(self.Yma, self.Yma),
559+
label="Mean Aerodynamic Chord",
560+
color="#467821",
561+
)
562+
563+
# Center Line
564+
center_line = plt.Line2D(
565+
(self.rootChord / 2, self.rootChord / 2),
566+
(0, self.span),
567+
color="#7A68A6",
568+
alpha=0.35,
569+
linestyle="--",
570+
label="Center Line",
571+
)
572+
573+
# Center of pressure
574+
cp_point = [abs(self.distanceToCM - self.cpz), self.Yma]
575+
576+
# Plotting
577+
fig3 = plt.figure(figsize=(4, 4))
578+
with plt.style.context("bmh"):
579+
ax1 = fig3.add_subplot(111)
580+
ax1.add_patch(el)
581+
ax1.add_line(Yma_line)
582+
ax1.add_line(center_line)
583+
ax1.scatter(
584+
*cp_point, label="Center Of Pressure", color="red", s=100, zorder=10
585+
)
586+
ax1.scatter(*cp_point, facecolors="none", edgecolors="red", s=500, zorder=10)
587+
588+
# Plot settings
589+
ax1.set_xlim(0, self.rootChord)
590+
ax1.set_ylim(0, self.span * 1.1)
591+
ax1.set_xlabel("Root Chord")
592+
ax1.set_ylabel("Span")
593+
ax1.set_title("Elliptical Fin")
594+
ax1.legend(bbox_to_anchor=(1.05, 1.0), loc="upper left")
595+
596+
return self
597+
450598

451599
class Tail:
452600
"""Class that defines a tail for the rocket.

0 commit comments

Comments
 (0)