Skip to content

Instantly share code, notes, and snippets.

@AB9IL
Last active April 23, 2022 15:58
Show Gist options
  • Save AB9IL/f0ff895f078f9fbd7c33f451208f4a02 to your computer and use it in GitHub Desktop.
Save AB9IL/f0ff895f078f9fbd7c33f451208f4a02 to your computer and use it in GitHub Desktop.
A Python script which creates plots useful for building parabolic reflectors.
#!/usr/bin/python3
# Copyright (c) by Philip Collier, github.com/AB9IL
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version. There is NO warranty; not even for
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from math import sqrt, pow
# See see nicely written mathematical basis for
# defining the parabola and focus:
# http://physicsinsights.org/parabola_focus.html
# y is the axis of the parabola
# the directrix is below zero and parallels the x axis
# y = x**2 and also y = a * x***2 + b *x + c
# Keep it simple: make b and c equal to zero
# Work directly with the focus and compute the curve.
# parabola parameters
# the focus = f
f = 5
# set up some text
g = f + 2
text_1 = " Focus: (0, " + str(f) + ")"
#####################################################
# do not change these or you lose the parabolic curve
a = 1 / (4 * f)
b = 0
c = 0
# Descriptive text
i = f + 4
text_0 = "Parabola: " + str(a) + " * x^2 + " + str(b) + \
" * x " + "+ " + str(c)
# Defining the range of input values on the horizontal axis
x_values = [x for x in range(-12, 13)]
# Computing the values of the standard parabola
# for different values in x_values
y_values = [a * (pow(x, 2) + b * x + c) for x in x_values]
plt.style.use('seaborn-darkgrid')
fig, ax = plt.subplots()
ax.plot(x_values, y_values, linewidth=1)
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
ax.yaxis.set_major_locator(ticker.MultipleLocator(1))
plt.scatter(0, f)
plt.text(-8, i, text_0)
plt.text(-4, g, text_1)
plt.axis('square')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment