JXG.Curve

Class

Curves are the common object for function graphs, parametric curves, polar curves, and data plots. Creates a new curve object. Do not use this constructor to create a curve. Use JXG.Board#create with type Curve, or Functiongraph instead.

Attributes

Own

lineCap

Description

Line endings (linecap) of a curve stroke. Possible values are:

  • 'butt',
  • 'round',
  • 'square'.
Type
String
Overrides
JXG.GeometryElement#lineCap
Default Value
'round'
Source
options.js, line 5315

Inherited

Members

Own

dataX : array

Description

Array holding the x-coordinates of a data plot. This array can be updated during run time by overwriting the method JXG.Curve#updateDataArray.

Type
array
Source
base/curve.js, line 83

dataY : array

Description

Array holding the y-coordinates of a data plot. This array can be updated during run time by overwriting the method JXG.Curve#updateDataArray.

Type
array
Source
base/curve.js, line 91

numberPoints

Description

Number of points on curves. This value changes between numberPointsLow and numberPointsHigh. It is set in JXG.Curve#updateCurve.

Source
base/curve.js, line 73

qdt : JXG.Math.Quadtree

Description

Stores a quadtree if it is required. The quadtree is generated in the curve updates and can be used to speed up the hasPoint method.

Type
JXG.Math.Quadtree
Source
base/curve.js, line 107

ticks : Array

Description

Array of ticks storing all the ticks on this curve. Do not set this field directly and use JXG.GeometryElement#addTicks and JXG.GeometryElement#removeTicks to add and remove ticks to and from the curve.

Type
Array
See
Source
base/curve.js, line 100

Inherited

Methods

Own

Ft(t) → {Array}

Return the homogeneous coordinates of the curve at t - including all transformations applied to the curve.

Parameters

Name Type Description
t Number

A number between JXG.Curve#minX and JXG.Curve#maxX.

Returns

[Z(t), X(t), Y(t)] plus transformations

Type
Array

Details

Source
base/curve.js, line 239

X(t, suspendUpdate) → {Number}

The parametric function which defines the x-coordinate of the curve.

Parameters

Name Type Description
t Number

A number between JXG.Curve#minX and JXG.Curve#maxX.

suspendUpdate Boolean

A boolean flag which is false for the first call of the function during a fresh plot of the curve and true for all subsequent calls of the function. This may be used to speed up the plotting of the curve, if the e.g. the curve depends on some input elements.

Returns

x-coordinate of the curve at t.

Type
Number

Details

Source
base/curve.js, line 207

Y(t, suspendUpdate) → {Number}

The parametric function which defines the y-coordinate of the curve.

Parameters

Name Type Description
t Number

A number between JXG.Curve#minX and JXG.Curve#maxX.

suspendUpdate Boolean

A boolean flag which is false for the first call of the function during a fresh plot of the curve and true for all subsequent calls of the function. This may be used to speed up the plotting of the curve, if the e.g. the curve depends on some input elements.

Returns

y-coordinate of the curve at t.

Type
Number

Details

Source
base/curve.js, line 220

Z(t) → {Number}

Treat the curve as curve with homogeneous coordinates.

Parameters

Name Type Description
t Number

A number between JXG.Curve#minX and JXG.Curve#maxX.

Returns

Always 1.0

Type
Number

Details

Source
base/curve.js, line 229

addTransform(transform) → {JXG.Curve}

Add transformations to this curve.

Parameters

Name Type Description
transform JXG.Transformation | Array

Either one JXG.Transformation or an array of JXG.Transformations.

Returns

Reference to the curve object.

Type
JXG.Curve

Details

Overrides
JXG.GeometryElement#addTransform
Source
base/curve.js, line 921

allocatePoints()

Allocate points in the Coords array this.points

Details

Source
base/curve.js, line 409

generateTerm(varname, xterm, yterm, miopt, maopt)

Converts the JavaScript/JessieCode/GEONExT syntax of the defining function term into JavaScript. New methods X() and Y() for the Curve object are generated, further new methods for minX() and maxX(). If mi or ma are not supplied, default functions are set.

Parameters

Name Type Attributes Description
varname String

Name of the parameter in xterm and yterm, e.g. 'x' or 't'

xterm String | Number | function | Array

Term for the x coordinate. Can also be an array consisting of discrete values.

yterm String | Number | function | Array

Term for the y coordinate. Can also be an array consisting of discrete values.

mi String | Number | function <optional>

Lower bound on the parameter

ma String | Number | function <optional>

Upper bound on the parameter

Details

See
Source
base/curve.js, line 1050

getCoords() → {Array}

Return the points of the curve as array of length-three-arrays [z, x, y], i.e. return an array of homogeneous coordinates. The returned coordinates are in user coordinates. Finite homogeneous coordinates have the first value set to 1, i.e. it can be ignored.

The points of the curve are either the elements of the properties dataX and dataY or the result of the plotting algorithm. In any case, the points are stored in the private property "points".

Returns

Type
Array

Details

Source
base/curve.js, line 1498

getLabelPosition(pos, distance) → {JXG.Coords}

Position a curve label according to the attributes "position" and distance. This function is also used for angle, arc and sector.

Parameters

Name Type Description
pos String
distance Number

Returns

Type
JXG.Coords

Details

Source
base/curve.js, line 1171

(private) getTransformationSource() → {Array}

If the curve is the result of a transformation applied to a continuous curve, the glider projection has to be done on the original curve. Otherwise there will be problems when changing between high and low precision plotting, since there number of points changes.

Returns

[Boolean, curve]: Array contining 'true' if curve is result of a transformation, and the source curve of the transformation.

Type
Array

Details

Source
base/curve.js, line 1473

hasPoint(x, y, start) → {Boolean}

Checks whether (x,y) is near the curve.

Parameters

Name Type Description
x Number

Coordinate in x direction, screen coordinates.

y Number

Coordinate in y direction, screen coordinates.

start Number

Optional start index for search on data plots.

Returns

True if (x,y) is near the curve, False otherwise.

Type
Boolean

Details

Overrides
JXG.GeometryElement#hasPoint
Source
base/curve.js, line 260

(private) interpolationFunctionFromArray(which) → {function}

Generate the method curve.X() in case curve.dataX is an array and generate the method curve.Y() in case curve.dataY is an array.

Parameters

Name Type Description
which String

Either 'X' or 'Y'

Returns

Type
function

Details

Source
base/curve.js, line 958

maxX() → {Number}

Gives the default value of the right bound for the curve. May be overwritten in JXG.Curve#generateTerm.

Returns

Right bound for the curve.

Type
Number

Details

Source
base/curve.js, line 182

minX() → {Number}

Gives the default value of the left bound for the curve. May be overwritten in JXG.Curve#generateTerm.

Returns

Left bound for the curve.

Type
Number

Details

Source
base/curve.js, line 161

moveTo(where) → {JXG.Curve}

Shift the curve by the vector 'where'.

Parameters

Name Type Description
where Array

Array containing the x and y coordinate of the target location.

Returns

Reference to itself.

Type
JXG.Curve

Details

Source
base/curve.js, line 1441

notifyParents(contentStr)

Finds dependencies in a given term and notifies the parents by adding the dependent object to the found objects child elements.

Parameters

Name Type Description
contentStr String

String containing dependencies for the given object.

Details

Source
base/curve.js, line 1135

update() → {JXG.Curve}

Generates points of the curve to be plotted.

Returns

Reference to the curve object.

Type
JXG.Curve

Details

Overrides
JXG.GeometryElement#update
See
Source
base/curve.js, line 431

updateCurve() → {JXG.Curve}

Computes the curve path

Returns

Reference to the curve object.

Type
JXG.Curve

Details

See
Source
base/curve.js, line 749

updateDataArray()

For dynamic dataplots updateCurve can be used to compute new entries for the arrays JXG.Curve#dataX and JXG.Curve#dataY. It is used in JXG.Curve#updateCurve. Default is an empty method, can be overwritten by the user.

Examples

// This example overwrites the updateDataArray method.
// There, new values for the arrays JXG.Curve.dataX and JXG.Curve.dataY
// are computed from the value of the slider N

var N = board.create('slider', [[0,1.5],[3,1.5],[1,3,40]], {name:'n',snapWidth:1});
var circ = board.create('circle',[[4,-1.5],1],{strokeWidth:1, strokecolor:'black', strokeWidth:2,
		fillColor:'#0055ff13'});

var c = board.create('curve', [[0],[0]],{strokecolor:'red', strokeWidth:2});
c.updateDataArray = function() {
        var r = 1, n = Math.floor(N.Value()),
            x = [0], y = [0],
            phi = Math.PI/n,
            h = r*Math.cos(phi),
            s = r*Math.sin(phi),
            i, j,
            px = 0, py = 0, sgn = 1,
            d = 16,
            dt = phi/d,
            pt;

        for (i = 0; i < n; i++) {
            for (j = -d; j <= d; j++) {
                pt = dt*j;
                x.push(px + r*Math.sin(pt));
                y.push(sgn*r*Math.cos(pt) - (sgn-1)*h*0.5);
            }
            px += s;
            sgn *= (-1);
        }
        x.push((n - 1)*s);
        y.push(h + (sgn - 1)*h*0.5);
        this.dataX = x;
        this.dataY = y;
    }

var c2 = board.create('curve', [[0],[0]],{strokecolor:'red', strokeWidth:1});
c2.updateDataArray = function() {
        var r = 1, n = Math.floor(N.Value()),
            px = circ.midpoint.X(), py = circ.midpoint.Y(),
            x = [px], y = [py],
            phi = Math.PI/n,
            s = r*Math.sin(phi),
            i, j,
            d = 16,
            dt = phi/d,
            pt = Math.PI*0.5+phi;

        for (i = 0; i < n; i++) {
            for (j= -d; j <= d; j++) {
                x.push(px + r*Math.cos(pt));
                y.push(py + r*Math.sin(pt));
                pt -= dt;
            }
            x.push(px);
            y.push(py);
            pt += dt;
        }
        this.dataX = x;
        this.dataY = y;
    }
    board.update();

// This is an example which overwrites updateDataArray and produces
// a Bezier curve of degree three.
var A = board.create('point', [-3,3]);
var B = board.create('point', [3,-2]);
var line = board.create('segment', [A,B]);

var height = 0.5; // height of the curly brace

// Curly brace
var crl = board.create('curve', [[0],[0]], {strokeWidth:1, strokeColor:'black'});
crl.bezierDegree = 3;
crl.updateDataArray = function() {
    var d = [B.X()-A.X(), B.Y()-A.Y()],
        dl = Math.sqrt(d[0]*d[0]+d[1]*d[1]),
        mid = [(A.X()+B.X())*0.5, (A.Y()+B.Y())*0.5];

    d[0] *= height/dl;
    d[1] *= height/dl;

    this.dataX = [ A.X(), A.X()-d[1], mid[0], mid[0]-d[1], mid[0], B.X()-d[1], B.X() ];
    this.dataY = [ A.Y(), A.Y()+d[0], mid[1], mid[1]+d[0], mid[1], B.Y()+d[0], B.Y() ];
};

// Text
var txt = board.create('text', [
                    function() {
                        var d = [B.X()-A.X(), B.Y()-A.Y()],
                            dl = Math.sqrt(d[0]*d[0]+d[1]*d[1]),
                            mid = (A.X()+B.X())*0.5;

                        d[1] *= height/dl;
                        return mid-d[1]+0.1;
                    },
                    function() {
                        var d = [B.X()-A.X(), B.Y()-A.Y()],
                            dl = Math.sqrt(d[0]*d[0]+d[1]*d[1]),
                            mid = (A.Y()+B.Y())*0.5;

                        d[0] *= height/dl;
                        return mid+d[0]+0.1;
                    },
                    function() { return "length=" + JXG.toFixed(B.Dist(A), 2); }
                ]);


board.update(); // This update is necessary to call updateDataArray the first time.

Details

Source
base/curve.js, line 740

updateRenderer() → {JXG.Curve}

Updates the visual contents of the curve.

Returns

Reference to the curve object.

Type
JXG.Curve

Details

Overrides
JXG.GeometryElement#updateRenderer
Source
base/curve.js, line 446

updateTransform(p) → {JXG.Point}

Applies the transformations of the curve to the given point p. Before using it, JXG.Curve#updateTransformMatrix has to be called.

Parameters

Name Type Description
p Point

Returns

The given point.

Type
JXG.Point

Details

Source
base/curve.js, line 904

Inherited

Events

Own

none

Inherited

Parameters

Name Type Description
board String | JXG.Board

The board the new curve is drawn on.

parents Array

defining terms An array with the function terms or the data points of the curve.

attributes Object

Defines the visual appearance of the curve.

Details

See
Source
base/curve.js, line 64

Extends