Skip to content

A graphing library for implicit equations, in Clojure

License

Notifications You must be signed in to change notification settings

rm-hull/implicit-equations

Repository files navigation

Implicit Equations

Build Status Coverage Status Dependencies Status Maintenance

In mathematics, an implicit equation is a relation of the form R(x1,...,xn) = 0, where R is a function of several variables (often a polynomial). For example, the implicit equation of the unit circle is x2 + y2 - 1 = 0.

Examples

Given an X/Y equation (using the infix library):

(use 'implicit-equations.plot)
(use 'infix.macros)

(defn quadrifolium [x y]
  (infix (x ** 2 + y ** 2) ** 3 - x ** 2 * y ** 2))

By specifying some bounds, we can now render to PNG images, with the draw command - this renders onto a BufferedImage when the equation crosses zero:

(draw quadrifolium "graph.png" {:bounds 1 :line-width 4})

to produce:

PNG

Other equations produce the following plots:

Knot Curve

PNG

(defn knot-curve [x y]
  (infix (x ** 2 - 1) ** 2 - y ** 2 . (3 + 2 . y)))

Biology

PNG

(defn biology [x y]
  (infix sin(sin x + cos y) - cos(sin(x . y) + cos x)))

Chain-mesh

PNG

(defn chain-mesh [x y]
  (infix sin((x ** 2) + (y ** 2)) - cos(x . y)))

Checkerboard

PNG

(defn checkerboard [x y]
  (infix exp(sin x + cos y) - sin(exp(x + y))))

Dizzy

PNG

(defn dizzy [x y]
  (infix abs(sin(x ** 2 - y ** 2)) - (sin(x + y) + cos(x . y))))

Glint

PNG

(defn glint [x y]
  (infix abs(sin(x ** 2 + 2 . x . y)) - sin(x - 2 . y)))

Spira

PNG

(defn spira [x y]
  (infix sin(x ** 2 + y ** 2) - sin(x ÷ y ** 2))

Bands

PNG

(defn bands [x y]
  (infix sin(1 - x ** 2) . sin(2 - y ** 2) . x . y - cos (2 - y ** 2)))

Refined from: http://mathematica.stackexchange.com/questions/19590/what-is-a-good-way-to-plot-some-difficult-implicit-equations

References

License

The MIT License (MIT)

Copyright (c) 2016 Richard Hull

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A graphing library for implicit equations, in Clojure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published