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!

Beizer curves

by sonone, Apr 18, 2023, 2:20 PM

Beizer curves

Using complex numbers to represent coordinates, I made a simple program to draw a beizer curve:
Cls
ViewWindow -6.3,6.3,1,-3.1,3.1,1
{0,2-2i,3+3i}->List 1  'curve coordinates
0.05->A                'step size
Plot ReP List 1[1],ImP List 1[1]
For A->I To 1 Step A 
List 1->List 2
Dim List 1->N 
While N>1
Dsz N
For 1->J To N
List 2[J]+I*(List 2[J+1]-List 2[J])->List 2[J]
Next
WhileEnd
Plot ReP List 2[1],ImP List 2[1]
Line
Next

I coded this on my CASIO fx-9860G Slim, but it should work on all other CASIO fx with CASIO-BASIC.

Direction field generator for TI 84 plus CE python

by sonone, Jan 30, 2023, 3:12 PM

Have you every got the feeling, when you are taking ordinary differential equations, and they ask you to use technology to graph the direction field for some differential equation $y^\prime=f(x,y)$? Did you ever wish that your graphing calculator could be that "technology"? That is how I felt, and after numerous versions I have made a beautiful and simplistic direction field program in python, designed for a TI 84 plus CE with the python app.

Here are the pros and cons of the python program:
Pros:
  • Thin lines make slopes easy to estimate
  • Features colored lines (negative slopes= blue, positive slopes = red)
  • Will trace the approximate solution from a point with a custom step interval
Cons:
  • You need to update the function in the code itself

To use the program you need to first specify the function in the commented section of the code. When you run it it will ask you for the dimensions of the screen you want to graph and for the spacing of the lines. Then the program will prompt you too trace approximate solution. If you enter 0 (no), it will draw the direction field. If you enter 1 (yes) it will draw the direction field AND the traced line.

installation instructions
Attachments:
DIRFIELD.py (1kb)
This post has been edited 1 time. Last edited by sonone, Jan 31, 2023, 8:22 PM
Reason: Added file

AoPS avatar drawer

by sonone, Aug 5, 2022, 9:14 PM

AoPS avatar drawer
I made a program that draws an AoPS avatar, but it can do more! If desired, one can create custom avatars of most any size (I doubt some of the larger sizes render well at all on a 126x62 resolution display). It only supports plane partitions (i.e. a normal avatars), otherwise it will look like scribble scrabble.

The height matrix give information on high each "pillar" is. The AoPS logo has a height matrix of
[[3,3,3][3,2,1][3,1,1]]
The first row is the back right, the columns counting up to the right.

If you so desire to change the size, say to a 5x5x5, go to the beginning of the code and change S to 5 (default is 3). Then edit the assignment for MAT A to a 5x5 height matrix. Then run the program and it should render. If it looks strange, check the height matrix to make sure that the values are correct.

The program is called AOPSAVTR and takes up 492 bytes of memory. The .g1m file is attached below. I had to attach it as a .zip file since AoPS doesn't recognize.g1m files.
Attachments:
AOPSAVTR.g1m.zip (0kb)
This post has been edited 1 time. Last edited by sonone, Aug 5, 2022, 9:26 PM

CASIO BASIC programming tips: Text display functions

by sonone, May 9, 2022, 11:26 PM

Text display functions
In programs, you can utilize two different display windows: the graphing window and the text window. The graphing window if where graphing and any type of drawing happens, and the text window is for almost everything else (I say almost, because there are list, table and matrix views, which are different beasts in themselves). I will be focusing on the text window display functions which display text and strings.

The first and easiest is just string output. Simply place a string in its own line and it will print in the console. For example,
"TEXT"

just prints out TEXT to the console.
Akin to this is the output function. It is a little triangle in the pgrm menu which acts the same as the simple string output, except that it requires you to press EXE to continue program execution. If the argument is a string, the display is left flushed, but if it is a number or variable, it is right flushed. For example (/ means the output function):
"PRESS EXE"/
3/
"TEXT"

gives
PRESS EXE
                            -Disp-

<Press EXE>
PRESS EXE
                                 3
                             -Disp-

<Press EXE again>
PRESS EXE
                                  3
                             -Disp-
TEXT

Note: if you use the output function as the last call of your program, it will re-display the last outputted value once you press EXE and then exit the program if you press it again.

The last display function, found in the I/O of prgm menu, is Locate. This is my favorite display function because I can put anything I want on the text window anywhere. The syntax is
Locate <COL 1-21>, <ROW 1-7>, <arg (str, var, num etc)>

The following code puts 7 A's in a diagonal line:
Locate 1,1,"A"
Locate 2,2,"A"
Locate 3,3,"A"
Locate 4,4,"A"
Locate 5,5,"A"
Locate 6,6,"A"
Locate 7,7,"A"

A more efficient code using a for loop
Output:
A
 A
  A
   A
    A
     A
      A


For my coding I generally use the first two display functions in computational programs, while I almost exclusively use Locate for any games. I will cover the basic graphing displays in another post.

SUBSHOT: program in CASIO BASIC

by sonone, May 3, 2022, 8:49 PM

SUBSHOT: Submarine Sinking Game
This is one of my earlier games inspired when I was learning projectile motion in physics. The object of the game is simple: sink as many subs as you can in ten shots. Depending on where you shoot determines how much damage the sub takes. The game methodology is as follows:
  • Draw board
  • Position gun
  • Fire gun and calculate hit
  • Update stats
The shooting mechanism is vector based. There is a pixel you can move around the screen that acts as the head of the initial velocity vector. The longer the vector the father it shoots etc. Using this information the program calculates the final location using 2D kinematics equations.

I have attached two pictures of what the game looks like on the calculator, one is the initial screen and the other is after the first shot.

The code is rather lengthy and not appealing to type out right now. If the code is asked for I will endeavor to type it up ASAP.
Attachments:

REVIVAL: programming graphing calculators

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

REVIVAL
The reason I haven't been posting lately is mainly I had a lot of school, but also that when I wasn't doing school I was programming my graphing calculator(s). I have become pretty comfortable with CASIO BASIC have made programs ranging from the quadratic formula to a sub-sinking game.
I will be posting about some of the programs I have created, and some little programming tips for CASIO calculators.

I have a CASIO fx-9750GII and an fx-9860G Slim that I code with BASIC, and a TI Nspire CX II CAS, which supports TI BASIC, Python, and lua scripting (I haven't learned lua, yet). The majority of my posts from here on out will be on CASIO programming, but I might occasionally post a little thing about python or TI BASIC.

Lastly, before I finish, I will give some teasers on what programs I have already completed:
  • Drawing a direction field for a two-variable function
  • Using Euler's method to approximate the value of a first order DE
  • Converting a matrix to its reduced row echelon form
  • My own version of Subway-Surfers
  • Day-of-the-week finder for date in Gregorian calendar
  • Radical simplifier
  • Quadratic formula
  • Submarine sinking game (ballistic missile game)
  • And more...

Connect Four with CASIO BASIC

by sonone, Jun 16, 2021, 3:56 PM

Hey everyone!
I made a Connect Four (two players) program on my CASIO fx-9750GII using the CASI BASIC programming language.
Here are the features:
Press the left and right arrows to move columns
The EXE button places your chip
When a column is full, the $\uparrow$ will become a $\times$ on the column
You win by getting four of the same chips in a row vertically, horizontally or diagonally
Here is some other useful info:
Uses 1084 bytes of memory
119 lines

BAISC code

P.S. I learned CASIO BASIC from the software guide (too large to attach), if anyone is interested. Page 212 (8-1)

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

Easy way to delete your post in another user's blog

by sonone, May 17, 2021, 6:57 PM

Here is a really easy way to delete your post in another user's blog.
Step 1: Inspect Element
Right click on the report button, and click "Inspect Element". h

Step 2: Locate line
There should be a highlighted line. Right click and do to "Edit", then click "HTML". h

Step 3: Edit HTML
Change "blog-report-post" to "blog-delete-post". h

Step 4: Click the "Report" button
Click out of the editing area and click "Repot". h

Step 5: Delete post
Click "OK" and POOF!, your post is gone. h
You can also edit a post in a similar fashion.
This post has been edited 1 time. Last edited by sonone, May 17, 2021, 7:00 PM

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: 4919
  • Total comments: 146
Search Blog
a