Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Latest commit

 

History

History
94 lines (67 loc) · 3.51 KB

README.md

File metadata and controls

94 lines (67 loc) · 3.51 KB

Conic Sections Plotter

What is this?

Short story: I was bored in Maths, I started writing this plotter thingie to better understand these things.

It's not perfect. It's just a learning tool for me and anyone else who wants to look at this mess of code. It was done in only a few maths classes.

How to use

Edit formulas by editing the characters marked in a reddish-yellowish background colour. If you don't have anything, the variable name will be shown instead.

You can also choose between formulas by selecting the tabs above.

Known Issues/Feature Wishlist

  • Graph doesn't change on input
  • Additional information on the graph

Design

I've decided to keep the equations seperate from the code (as in kept the in their own objects rather than intertwine them).

They are stored in the modes objects and called up when needed.

They all have their title, the equation visiable and editable by the user, a function which calculates y, whether it needs to be dualSided since Math.sqrt() only returns the positive result, required parameters and an unused properties object.

line: {
    title: "Line",
    equation: "y = $mx + $c",
    y: function(x)
    {
        var m = eval(equVars["m"])
        var c = eval(equVars["c"])

        // y = mx + c
        return (m * x) + c
    },
    dualSided: false,
    parameters: [ "m", "c" ],
    properties: { ... },  // Unused
}

Conic Sections

Straight Line

Equation: y = mx + c

return (m * x) + c

Circle

Equation: r^2 = (x - h)^2 + (y - k)^2

Rearranged into: \sqrt{r^2 - (x-h)^2} + k

return Math.sqrt(Math.pow(r, 2) - Math.pow(x - h, 2)) + k

Ellipse

Equation: 1 = \frac{(x-h)^2}{a^2}+\frac{(y-k)^2}{b^2}

Rearranged into: \sqrt{b^2 \left(1 - \frac{(x-h)^2}{a^2}\right)} + k

return Math.sqrt(Math.pow(b, 2) * (1 - (Math.pow(x - h, 2) / Math.pow(a, 2)))) + k

Parabola (Horizontal)

Equation: (y-k)^2 = 4a(x-h)

Rearranged into: \sqrt{4a(x-h)} + k

return Math.sqrt(4 * a * (x - h)) + k

Parabola (Vertical)

Equation: y - k = 4a(x - h)^2

Rearranged into: 4a(x-h^2) + k

return 4 * a * Math.pow(x - h, 2) + k

Hyperbola

Equation: 1 = \frac{(x-h)^2}{a^2} - \frac{(y-k)^2}{b^2}

Rearranged into: \sqrt{ b^2\left(\frac{ (x - k)^2 }{a^2} \right) - 1} + k

return Math.sqrt(Math.pow(b, 2) * ((Math.pow(x - h, 2) / Math.pow(a, 2))) - 1) + k