Something I forgot about parabolas

by sonone, Jul 13, 2023, 2:22 PM

I was recently making a calculator program to generate equations for various graphs, and while researching parabolas I came across something I had forgotten about.

Most of us probably learned parabolas as $y=ax^2+bx+c$ or $y=a(x-h)^2+k$, right? But they are much more than an equation. Take a horizontal line and any point in a plane. We call the line the directrix and the point the focus. [asy]
size(100);
draw((-5,0)--(5,0), darkgreen,Arrows(TeXHead));
dot((0,3), red);
label("directrix",(0,0),S,darkgreen);
label("focus",(0,3),N,red);
[/asy]
To generate a parabola, we take the locus of points equidistant from the focus and directrix.
[asy]
size(100);

pair parabola(pair focus, real directrix, real x) {
	pair vertex = (focus.x, (focus.y-directrix)/2);
	real mindist = vertex.y-directrix;
	return (x, 1/(4*mindist)*x^2-vertex.x/(2*mindist)+vertex.x^2/(2*mindist)+vertex.y);
}

draw((-5,0)--(5,0), darkgreen,Arrows(TeXHead));
dot((0,3), red);
pair p1 = parabola((0,3),0,-2);

draw((-2,0)--p1--(0,3), blue);
dot(p1,green);
[/asy]
If we do this for a lot a points we get something like this:
[asy]
size(100);

pair parabola(pair focus, real directrix, real x) {
	pair vertex = (focus.x, (focus.y-directrix)/2);
	real mindist = vertex.y-directrix;
	return (x, 1/(4*mindist)*x^2-vertex.x/(2*mindist)+vertex.x^2/(2*mindist)+vertex.y);
}

draw((-5,0)--(5,0), darkgreen,Arrows(TeXHead));
dot((0,3), red);

pair last = parabola((0,3),0,-4);
for (real i = -4; i <= 4; ++i) {
pair p1 = parabola((0,3),0,i);
draw(last--p1,orange);
last = p1;
draw((i,0)--p1--(0,3), blue);
dot(p1,green);
}
dot((0,3), red);
[/asy]
Note that the vertex of the parabola is where the distance is minimized.

This definition seems trivial, but it gets interesting when the line is not horizontal:
[asy]
size(100);

pair parabola(pair focus, real directrix, real x) {
	pair vertex = (focus.x, (focus.y-directrix)/2);
	real mindist = vertex.y-directrix;
	return (1/(4*mindist)*x^2-vertex.x/(2*mindist)+vertex.x^2/(2*mindist)+vertex.y,x);
}

draw((0,-5)--(0,5), darkgreen,Arrows(TeXHead));
dot((3,0), red);

pair last = parabola((0,3),0,-4);
for (real i = -4; i <= 4; i+=.5) {
pair p1 = parabola((0,3),0,i);
draw(last--p1,orange);
last = p1;
}
dot((3,0), red);
[/asy]

You can even create slanted parabolas (although you do end up with implicit equations):
[asy]
size(100);

pair parabola(pair focus, real directrix, real x) {
	pair vertex = (focus.x, (focus.y-directrix)/2);
	real mindist = vertex.y-directrix;
	return (x, 1/(4*mindist)*x^2-vertex.x/(2*mindist)+vertex.x^2/(2*mindist)+vertex.y);
}

picture para;
draw(para,(-5,0)--(5,0), darkgreen,Arrows(TeXHead));
dot(para,(0,3), red);

pair last = parabola((0,3),0,-4);
for (real i = -4; i <= 4; i+=.2) {
pair p1 = parabola((0,3),0,i);
draw(para,last--p1,orange);
last = p1;
}
dot(para,(0,3), red);
add(rotate(-60)*para);
[/asy]
I hope you enjoyed!

Function to turn a string into an int

by sonone, May 18, 2021, 12:35 PM

As requested by piphi here, I have made a function that turns a string into an integer (the default value is 0, if the string is not an integer).
int parse_int(string n) {
    int parse_digit(string n) {
        if (ascii(n) >= 48 && ascii(n) <= 57)
            return ascii(n) - 48;
        else
            return -1;
    } 
 
    bool is_int(string idk) {
        bool yes = true;
        string n;
 
        for (int i = 0; i < length(idk); ++i) {
            n = substr(idk, i, 1);
            if (parse_digit(n) == -1) {
                yes = false;
                break;
            }
        }
 
        return yes;
    }
 
    int multiplier = 1;
    int start_index = 0;
 
    if (substr(n,0,1) == "-") {
        multiplier = -1;
        start_index = 1;
    }
 
    if (is_int(n)) {
        int result = 0;
        for (int i = start_index; i < length(n); ++i) {
            result += parse_digit(substr(n,i,1))*10^(length(n) - i - 1);
          }
        return multiplier * result;
    }
    else {
        return 0;
    }
}
This post has been edited 1 time. Last edited by sonone, May 18, 2021, 12:37 PM
Reason: add link

Old material is mostly Asymptote, new material is calculator programming

avatar

sonone
Archives
+ April 2023
+ August 2022
+ April 2021
+ August 2020
Shouts
Submit
  • I still exist as well.

    by G.G.Otto, Aug 11, 2023, 2:44 AM

  • hello I'm still here lol

    by player01, Aug 6, 2022, 6:24 PM

  • [REVIVAL] I will start posting more calculator relating posts very soon. Even though school has been busy, I have been programming my calculators a decent amount, so I have a lot to share...

    by sonone, Feb 18, 2022, 10:29 PM

  • wow its been like 2.5 years since geo class

    by pieMax2713, Feb 4, 2022, 8:38 PM

  • @violin21, I've been very busy with school lately and haven't been able to add another lesson. I will when i get a free moment

    by sonone, Aug 19, 2021, 12:45 AM

  • ORZ CODER

    by samrocksnature, Aug 9, 2021, 9:57 PM

  • Could you make more Asymptote lessons on your "How to do Asymptote" blog?

    by violin21, Aug 9, 2021, 7:26 PM

  • You can take it, just C&P the CSS into your CSS area

    by sonone, Apr 17, 2021, 10:08 PM

  • how can we take the CSS if we have permission to not take it?

    by GoogleNebula, Apr 17, 2021, 5:22 PM

  • That is awesome!

    by sonone, Apr 15, 2021, 10:09 PM

  • I modified your dodecahedron and got:
    [asy]
    import three;
    import solids;
    size(300);
    currentprojection=orthographic(0,1.3,1.2);
    light(0,5,10);

    real phi=(sqrt(6)+1)/3;
    real g=(phi-1)/2;
    real s=1/2;
    real a=sqrt(1-phi*phi/4-g*g)+phi/2;

    triple[] d;
    d[0]=(phi

    by Andrew2019, Mar 26, 2021, 12:15 AM

  • Not too many, just changing the color here and there. I really like your CSS!

    by sonone, Feb 2, 2021, 10:35 AM

  • Nice!

    I see you're making changes to the CSS. :)

    by G.G.Otto, Feb 1, 2021, 9:26 PM

  • I'm learning Java now!

    by sonone, Feb 1, 2021, 5:56 PM

  • And I took part of it from CaptainFlint and then added a ton of modifications. ;)

    by G.G.Otto, Dec 1, 2020, 8:56 AM

98 shouts
Tags
About Owner
  • Posts: 2106
  • Joined: Aug 20, 2016
Blog Stats
  • Blog created: Mar 28, 2020
  • Total entries: 61
  • Total visits: 4949
  • Total comments: 146
Search Blog
a