Home :: Tutorials :: Geometry

  1. Introduction
  2. Reference
    1. Methods
      1. constructor
      2. init
      3. eval
      4. multiply
      5. simplify
      6. bisection
      7. toString
      8. getDerivative
      9. getRoots
      10. getRootsInInterval
      11. getLinearRoot
      12. getQuadraticRoots
      13. getCubicRoots
      14. getQuarticRoots
    2. Class Properties
      1. TOLERANCE
      2. ACCURACY
    3. Properties
      1. coefs
      2. degree
  3. Example
  4. Download

Introduction

Polynomial is a JavaScript object used to manipulate polynomials. This object was created to encapsulate root finding functions needed by the intersection methods in the Intersection object.

getCubicRoots() and getQuarticRoots() was derived from David Eberly's excellent game engine source which can be found at his site. If you are at all interested in 3D gaming algorithms, then I highly recommend his "3D Game Engine Design" book (ISBN 1-55860-593-2).

This code is used in the 2D Geometry section of this site.


Reference

Methods

constructor - new Polynomial(<coefficient>+);

init(<coefficient>+);

eval(x) : Number;

multiply(that) : Polynomial;

simplify();

bisection(min, max) : Number;

toString() : String;

getDerivative() : Polynomial;

getRoots() : Array;

getRootsInInterval(min, max) : Array;

getLinearRoot() : Array of Numbers;

getQuadraticRoots() : Array of Numbers;

getCubicRoots() : Array of Numbers;

getQuarticRoots() : Array of Numbers;

Class Properties

Properties


Example

This example creates 4 monomials. These are multiplied together, creating successively higher degree polynomials.

Each polynomial is plotted (red markers) using the eval() method. The toString() methods creates the text representation of the polynomial that is displayed to the right of the x-axis (the gray line). The getRoots() method is used to display the roots of each polynomial (blue markers).


Download

Polynomial.js - the Intersection object only

2D.js.gz - all objects needed to use this object and other 2D geometry objects