API Docs for: 0.99.4
Show:

JXG.Math.Geometry Class

Module: JXG

Math.Geometry namespace definition

Methods

_bezierBbox

(
  • curve
)
Array private

Computes the bounding box [minX, maxY, maxX, minY] of a Bezier curve segment from its control points.

Parameters:

  • curve Array

    Array of four coordinate arrays of length 2 defining a Bezier curve segment, i.e. [[x0,y0], [x1,y1], [x2,y2], [x3,y3]].

Returns:

Array:

Bounding box [minX, maxY, maxX, minY]

_bezierLineMeetSubdivision

(
  • red
  • blue
  • level
  • testSegment
)
Array private

Find intersections of Bezier curve segments with a line by recursive subdivision. Below maxlevel determine intersections by intersection line segments.

Parameters:

  • red Array

    Array of four coordinate arrays of length 2 defining the first Bezier curve segment, i.e. [[x0,y0], [x1,y1], [x2,y2], [x3,y3]].

  • blue Array

    Array of four coordinate arrays of length 2 defining the second Bezier curve segment, i.e. [[x0,y0], [x1,y1], [x2,y2], [x3,y3]].

  • level Number

    Recursion level

  • testSegment Boolean

    Test if intersection has to be inside of the segment or somewhere on the line defined by the segment

Returns:

_bezierListConcat

() private

Append list of intersection points to a list.

_bezierMeetSubdivision

(
  • red
  • blue
  • level
)
Array

Find intersections of two Bezier curve segments by recursive subdivision. Below maxlevel determine intersections by intersection line segments.

Parameters:

  • red Array

    Array of four coordinate arrays of length 2 defining the first Bezier curve segment, i.e. [[x0,y0], [x1,y1], [x2,y2], [x3,y3]].

  • blue Array

    Array of four coordinate arrays of length 2 defining the second Bezier curve segment, i.e. [[x0,y0], [x1,y1], [x2,y2], [x3,y3]].

  • level Number

    Recursion level

Returns:

Array:

List of intersection points (up to nine). Each intersction point is an array of length three (homogeneous coordinates) plus preimages.

_bezierOverlap

(
  • bb1
  • bb2
)
Boolean private

Decide if two Bezier curve segments overlap by comparing their bounding boxes.

Parameters:

  • bb1 Array

    Bounding box of the first Bezier curve segment

  • bb2 Array

    Bounding box of the second Bezier curve segment

Returns:

Boolean:

true if the bounding boxes overlap, false otherwise.

_bezierSplit

(
  • curve
)
Array private

Splits a Bezier curve segment defined by four points into two Bezier curve segments. Dissection point is t=1/2.

Parameters:

  • curve Array

    Array of four coordinate arrays of length 2 defining a Bezier curve segment, i.e. [[x0,y0], [x1,y1], [x2,y2], [x3,y3]].

Returns:

Array:

Array consisting of two coordinate arrays for Bezier curves.

affineDistance

(
  • array1
  • array2
  • [n]
)
Number

Calculates euclidean distance for two given arrays of the same length. If one of the arrays contains a zero in the first coordinate, and the euclidean distance is different from zero it is a point at infinity and we return Infinity.

Parameters:

  • array1 Array

    Array containing elements of type number.

  • array2 Array

    Array containing elements of type number.

  • [n] Number optional

    Length of the arrays. Default is the minimum length of the given arrays.

Returns:

Number:

Euclidean (affine) distance of the given vectors.

angle

(
  • A
  • B
  • C
)
Number deprecated

Defined in src/math/geometry.js:71

Deprecated: Use {@link JXG.Math.Geometry#rad} instead.

Calculates the angle (in radians) defined by the points A, B, C.

Parameters:

  • A JXG.Point,Array

    A point or [x,y] array.

  • B JXG.Point,Array

    Another point or [x,y] array.

  • C JXG.Point,Array

    A circle - no, of course the third point or [x,y] array.

Returns:

Number:

The angle in radian measure.

See also:

  • #rad
  • #trueAngle

angleBisector

(
  • A
  • B
  • C
  • [board=A.board]
)
JXG.Coords

Calculates a point on the bisection line between the three points A, B, C. As a result, the bisection line is defined by two points: Parameter B and the point with the coordinates calculated in this function. Does not work for ideal points.

Parameters:

Returns:

JXG.Coords:

Coordinates of the second point defining the bisection.

bezierArc

(
  • A
  • B
  • C
  • withLegs
  • sgn
)
Array

Generate the defining points of a 3rd degree bezier curve that approximates a circle sector defined by three arrays A, B,C, each of length three. The coordinate arrays are given in homogeneous coordinates.

Parameters:

  • A Array

    First point

  • B Array

    Second point (intersection point)

  • C Array

    Third point

  • withLegs Boolean

    Flag. If true the legs to the intersection point are part of the curve.

  • sgn Number

    Wither 1 or -1. Needed for minor and major arcs. In case of doubt, use 1.

Returns:

Array:

Array consosting of one array of x-coordinates and one array of y-coordinates, Suitable for updataDataArray.

bezierSegmentEval

(
  • t
  • curve
)
Array

Eval Bezier curve segment at value t.

Parameters:

  • t Number

    value at which the curve is evaluated

  • curve Array

    THe Bezier curve given by four coordinate pairs

Returns:

Array:

Value of the Bezier curve at t given as Euclidean coordinates in the form [1, x, y].

calcLineDelimitingPoints

(
  • el
  • point1
  • point2
)

A line can be a segment, a straight, or a ray. so it is not always delimited by point1 and point2.

This method adjusts the line's delimiting points taking into account its nature, the viewport defined by the board.

A segment is delimited by start and end point, a straight line or ray is delimited until it meets the boards boundaries. However, if the line has infinite ticks, it will be delimited by the projection of the boards vertices onto itself.

Parameters:

  • el JXG.Line

    Reference to a line object, that needs calculation of start and end point.

  • point1 JXG.Coords

    Coordinates of the point where line drawing begins. This value is calculated and set by this method.

  • point2 JXG.Coords

    Coordinates of the point where line drawing ends. This value is calculated and set by this method.

See also:

calcStraight

(
  • el
  • point1
  • point2
  • margin
)

A line can be a segment, a straight, or a ray. so it is not always delimited by point1 and point2 calcStraight determines the visual start point and end point of the line. A segment is only drawn from start to end point, a straight line is drawn until it meets the boards boundaries.

Parameters:

  • el JXG.Line

    Reference to a line object, that needs calculation of start and end point.

  • point1 JXG.Coords

    Coordinates of the point where line drawing begins. This value is calculated and set by this method.

  • point2 JXG.Coords

    Coordinates of the point where line drawing ends. This value is calculated and set by this method.

  • margin Number

    Optional margin, to avoid the display of the small sides of lines.

See also:

circumcenter

(
  • point1
  • point2
  • point3
  • [board=point1.board]
)
JXG.Coords

Calculates the center of the circumcircle of the three given points.

Parameters:

Returns:

JXG.Coords:

Coordinates of the center of the circumcircle of the given points.

circumcenterMidpoint

() deprecated

Please use JXG.Math.Geometry#circumcenter instead.

distance

(
  • array1
  • array2
  • [n]
)
Number

Calculates the euclidean norm for two given arrays of the same length.

Parameters:

  • array1 Array

    Array of Number

  • array2 Array

    Array of Number

  • [n] Number optional

    Length of the arrays. Default is the minimum length of the given arrays.

Returns:

Number:

Euclidean distance of the given vectors.

distPointLine

(
  • point
  • line
)
Number

Calculates the distance of a point to a line. The point and the line are given by homogeneous coordinates. For lines this can be line.stdform.

Parameters:

  • point Array

    Homogeneous coordinates of a point.

  • line Array

    Homogeneous coordinates of a line ([C,A,B] where Ax+By+C*z=0).

Returns:

Number:

Distance of the point to the line.

GrahamScan

(
  • points
)
Array

Calculate the complex hull of a point cloud.

Parameters:

  • points Array

    An array containing {@link JXG.Point}, {@link JXG.Coords}, and/or arrays.

Returns:

intersectionFunction

(
  • board
  • el1,el2,i
  • alwaysintersect.
)
Function

Generate the function which computes the coordinates of the intersection point. Primarily used in undefined.

Parameters:

  • board JXG.Board

    object

  • el1,el2,i JXG.Line,JXG.Circle_JXG.Line,JXG.Circle_Number

    The result will be a intersection point on el1 and el2. i determines the intersection point if two points are available:

    • i==0: use the positive square root,
    • i==1: use the negative square root.
    See further {@see JXG.Point#createIntersectionPoint}.
  • alwaysintersect. Boolean

    Flag that determines if segements and arc can have an outer intersection point on their defining line or circle.

Returns:

Function:

Function returning a {@see JXG.Coords} object that determines the intersection point.

isSameDir

(
  • p1
  • p2
  • i1
  • i2
)
Boolean private

The vectors p2-p1 and i2-i1 are supposed to be collinear. If their cosine is positive they point into the same direction otherwise they point in opposite direction.

Parameters:

Returns:

Boolean:

True, if p2-p1 and i2-i1 point into the same direction

isSameDirection

(
  • start
  • p
  • s
)
Boolean private

If you're looking from point "start" towards point "s" and can see the point "p", true is returned. Otherwise false.

Parameters:

  • start JXG.Coords

    The point you're standing on.

  • p JXG.Coords

    The point in which direction you're looking.

  • s JXG.Coords

    The point that should be visible.

Returns:

Boolean:

True, if from start the point p is in the same direction as s is, that means s-start = k*(p-start) with k>=0.

meet

(
  • el1
  • el2
  • i
  • board
)
JXG.Coords

Computes the intersection of a pair of lines, circles or both. It uses the internal data array stdform of these elements.

Parameters:

  • el1 Array

    stdform of the first element (line or circle)

  • el2 Array

    stdform of the second element (line or circle)

  • i Number

    Index of the intersection point that should be returned.

  • board Object

    Reference to the board.

Returns:

JXG.Coords:

Coordinates of one of the possible two or more intersection points. Which point will be returned is determined by i.

meetBezierCurveRedBlueSegments

(
  • red
  • blue
  • nr
)
Array private

Find the nr-th intersection point of two Bezier curves, i.e. curves with bezierDegree == 3.

Parameters:

  • red JXG.Curve

    Curve with bezierDegree == 3

  • blue JXG.Curve

    Curve with bezierDegree == 3

  • nr Number

    The number of the intersection point which should be returned.

Returns:

Array:

The homogeneous coordinates of the nr-th intersection point.

meetBeziersegmentBeziersegment

(
  • red
  • blue
  • testSegment
)
Array private

Find the nr-th intersection point of two Bezier curve segments.

Parameters:

  • red Array

    Array of four coordinate arrays of length 2 defining the first Bezier curve segment, i.e. [[x0,y0], [x1,y1], [x2,y2], [x3,y3]].

  • blue Array

    Array of four coordinate arrays of length 2 defining the second Bezier curve segment, i.e. [[x0,y0], [x1,y1], [x2,y2], [x3,y3]].

  • testSegment Boolean

    Test if intersection has to be inside of the segment or somewhere on the line defined by the segment

Returns:

Array:

Array containing the list of all intersection points as homogeneous coordinate arrays plus preimages [x,y], t_1, t_2] of the two Bezier curve segments.

meetCircleCircle

(
  • circ1
  • circ2
  • i
  • board
)
JXG.Coords

Intersection of two circles.

Parameters:

  • circ1 Array

    stdform of the first circle

  • circ2 Array

    stdform of the second circle

  • i Number

    number of the returned intersection point. i==0: use the positive square root, i==1: use the negative square root.

  • board JXG.Board

    Reference to the board.

Returns:

JXG.Coords:

Coordinates of the intersection point

meetCurveCurve

(
  • c1
  • c2
  • nr
  • t2ini
  • [board=c1.board]
  • [method='segment']
)
JXG.Coords

Compute an intersection of the curves c1 and c2. We want to find values t1, t2 such that c1(t1) = c2(t2), i.e. (c1_x(t1)-c2_x(t2),c1_y(t1)-c2_y(t2)) = (0,0).

Methods: segment-wise intersections (default) or generalized Newton method.

Parameters:

  • c1 JXG.Curve

    Curve, Line or Circle

  • c2 JXG.Curve

    Curve, Line or Circle

  • nr Number

    the nr-th intersection point will be returned.

  • t2ini Number

    not longer used.

  • [board=c1.board] JXG.Board optional

    Reference to a board object.

  • [method='segment'] String optional

    Intersection method, possible values are 'newton' and 'segment'.

Returns:

JXG.Coords:

intersection point

meetCurveLine

(
  • el1
  • el2
  • nr
  • [board=el1.board]
  • alwaysIntersect
)
JXG.Coords

Intersection of curve with line, Order of input does not matter for el1 and el2.

Parameters:

  • el1 JXG.Curve,JXG.Line

    Curve or Line

  • el2 JXG.Curve,JXG.Line

    Curve or Line

  • nr Number

    the nr-th intersection point will be returned.

  • [board=el1.board] JXG.Board optional

    Reference to a board object.

  • alwaysIntersect Boolean

    If false just the segment between the two defining points are tested for intersection

Returns:

JXG.Coords:

Intersection point. In case no intersection point is detected, the ideal point [0,1,0] is returned.

meetCurveLineContinuous

(
  • cu
  • li
  • nr
  • board
)
JXG.Coords

Intersection of line and curve, continuous case. Finds the nr-the intersection point Uses JXG.Math.Geometry#meetCurveLineDiscrete as a first approximation. A more exact solution is then found with undefined.

Parameters:

Returns:

JXG.Coords:

Intersection point

meetCurveLineContinuousOld

(
  • cu
  • li
  • nr
  • board
)
deprecated private

Intersection of line and curve, continuous case. Segments are treated as lines. Finding the nr-the intersection point works for nr=0,1 only.

BUG: does not respect cu.minX() and cu.maxX()

Parameters:

meetCurveLineDiscrete

(
  • cu
  • li
  • nr
  • board
  • testSegment
)
JXG.Coords

Intersection of line and curve, discrete case. Segments are treated as lines. Finding the nr-th intersection point should work for all nr.

Parameters:

Returns:

JXG.Coords:

Intersection point. In case no intersection point is detected, the ideal point [0,1,0] is returned.

meetCurveRedBlueSegments

(
  • red
  • blue
  • nr
)

Find the n-th intersection point of two curves named red (first parameter) and blue (second parameter). We go through each segment of the red curve and search if there is an intersection with a segemnt of the blue curve. This double loop, i.e. the outer loop runs along the red curve and the inner loop runs along the blue curve, defines the n-th intersection point. The segments are either line segments or Bezier curves of degree 3. This depends on the property bezierDegree of the curves.

Parameters:

meetLineBoard

(
  • line
  • board
  • margin
)
Array

Intersection of the line with the board

Parameters:

  • line Array

    stdform of the line

  • board JXG.Board

    reference to a board.

  • margin Number

    optional margin, to avoid the display of the small sides of lines.

Returns:

Array:

[intersection coords 1, intersection coords 2]

meetLineCircle

(
  • lin
  • circ
  • i
  • board
)
JXG.Coords

Intersection of line and circle.

Parameters:

  • lin Array

    stdform of the line

  • circ Array

    stdform of the circle

  • i Number

    number of the returned intersection point. i==0: use the positive square root, i==1: use the negative square root.

  • board JXG.Board

    Reference to a board.

Returns:

JXG.Coords:

Coordinates of the intersection point

meetLineLine

(
  • l1
  • l2
  • i
  • board
)
JXG.Coords

Intersection of two lines.

Parameters:

  • l1 Array

    stdform of the first line

  • l2 Array

    stdform of the second line

  • i Number

    unused

  • board JXG.Board

    Reference to the board.

Returns:

JXG.Coords:

Coordinates of the intersection point.

meetSegmentSegment

(
  • p1
  • p2
  • q1
  • q2
)
Array

Intersection of two segments.

Parameters:

  • p1 Array

    First point of segment 1 using homogeneous coordinates [z,x,y]

  • p2 Array

    Second point of segment 1 using homogeneous coordinates [z,x,y]

  • q1 Array

    First point of segment 2 using homogeneous coordinates [z,x,y]

  • q2 Array

    Second point of segment 2 using homogeneous coordinates [z,x,y]

Returns:

Array:

[Intersection point, t, u] The first entry contains the homogeneous coordinates of the intersection point. The second and third entry gives the position of the intersection between the two defining points. For example, the second entry t is defined by: intersection point = t*p1 + (1-t)*p2.

perpendicular

(
  • line
  • point
  • [board=point.board]
)
Array

Calculates the coordinates of a point on the perpendicular to the given line through the given point.

Parameters:

  • line JXG.Line

    A line.

  • point JXG.Point

    Point which is projected to the line.

  • [board=point.board] JXG.Board optional

    Reference to the board

Returns:

Array:

Array of length two containing coordinates of a point on the perpendicular to the given line through the given point and boolean flag "change".

projectCoordsToBeziersegment

(
  • pos
  • curve
  • start
)
Array

Finds the coordinates of the closest point on a Bezier segment of a JXG.Curve to a given coordinate array.

Parameters:

  • pos Array

    Point to project in homogeneous coordinates.

  • curve JXG.Curve

    Curve of type "plot" having Bezier degree 3.

  • start Number

    Number of the Bezier segment of the curve.

Returns:

Array:

The coordinates of the projection of the given point on the given Bezier segment and the preimage of the curve which determines the closest point.

projectCoordsToCurve

(
  • x
  • y
  • t
  • curve
  • [board=curve.board]
)
JXG.Coords

Calculates the coordinates of the projection of a coordinates pair on a given curve. In case of function graphs this is the intersection point of the curve and the parallel to y-axis through the given point.

Parameters:

  • x Number

    coordinate to project.

  • y Number

    coordinate to project.

  • t Number

    start value for newtons method

  • curve JXG.Curve

    Curve on that the point is projected.

  • [board=curve.board] JXG.Board optional

    Reference to a board.

Returns:

JXG.Coords:

Array containing the coordinates of the projection of the given point on the given graph and the position on the curve.

See also:

  • #projectPointToCurve

projectCoordsToPolygon

(
  • p
  • pol
)
Array

Calculates the coordinates of the closest orthogonal projection of a given coordinate array onto the border of a polygon.

Parameters:

Returns:

Array:

The coordinates of the closest projection of the given point to the border of the polygon.

projectCoordsToSegment

(
  • p
  • q1
  • q2
)
Array

Calculates the coordinates of the orthogonal projection of a given coordinate array on a given line segment defined by two coordinate arrays.

Parameters:

  • p Array

    Point to project.

  • q1 Array

    Start point of the line segment on that the point is projected.

  • q2 Array

    End point of the line segment on that the point is projected.

Returns:

Array:

The coordinates of the projection of the given point on the given segment and the factor that determines the projected point as a convex combination of the two endpoints q1 and q2 of the segment.

projectPointToBoard

(
  • point
  • [board]
)

Parameters:

projectPointToCircle

(
  • point
  • circle
  • [board=point.board]
)
JXG.Coords

Calculates the coordinates of the projection of a given point on a given circle. I.o.w. the nearest one of the two intersection points of the line through the given point and the circles center.

Parameters:

  • point JXG.Point,JXG.Coords

    Point to project or coords object to project.

  • circle JXG.Circle

    Circle on that the point is projected.

  • [board=point.board] JXG.Board optional

    Reference to the board

Returns:

JXG.Coords:

The coordinates of the projection of the given point on the given circle.

projectPointToCurve

(
  • point
  • curve
  • [board=point.board]
)
JXG.Coords

Calculates the coordinates of the projection of a given point on a given curve. Uses undefined.

Parameters:

  • point JXG.Point

    Point to project.

  • curve JXG.Curve

    Curve on that the point is projected.

  • [board=point.board] JXG.Board optional

    Reference to a board.

Returns:

JXG.Coords:

The coordinates of the projection of the given point on the given graph.

See also:

  • #projectCoordsToCurve

projectPointToLine

(
  • point
  • line
  • [board=point.board]
)
JXG.Coords

Calculates the coordinates of the orthogonal projection of a given point on a given line. I.o.w. the intersection point of the given line and its perpendicular through the given point.

Parameters:

  • point JXG.Point

    Point to project.

  • line JXG.Line

    Line on that the point is projected.

  • [board=point.board] JXG.Board optional

    Reference to a board.

Returns:

JXG.Coords:

The coordinates of the projection of the given point on the given line.

projectPointToPoint

(
  • point
  • dest
)
JXG.Coords

Trivial projection of a point to another point.

Parameters:

  • point JXG.Point

    Point to project (not used).

  • dest JXG.Point

    Point on that the point is projected.

Returns:

JXG.Coords:

The coordinates of the projection of the given point on the given circle.

projectPointToTurtle

(
  • point
  • turtle
  • [board=point.board]
)
JXG.Coords

Calculates the coordinates of the projection of a given point on a given turtle. A turtle consists of one or more curves of curveType 'plot'. Uses undefined.

Parameters:

  • point JXG.Point

    Point to project.

  • turtle JXG.Turtle

    on that the point is projected.

  • [board=point.board] JXG.Board optional

    Reference to a board.

Returns:

JXG.Coords:

The coordinates of the projection of the given point on the given turtle.

rad

(
  • A
  • B
  • C
)
Number

Calculates the internal angle defined by the three points A, B, C if you're going from A to C around B counterclockwise.

Parameters:

  • A JXG.Point,Array

    Point or [x,y] array

  • B JXG.Point,Array

    Point or [x,y] array

  • C JXG.Point,Array

    Point or [x,y] array

Returns:

Number:

Angle in radians.

See also:

  • #trueAngle

reflection

(
  • line
  • point
  • [board=point.board]
)
JXG.Coords

Reflects the point along the line.

Parameters:

  • line JXG.Line

    Axis of reflection.

  • point JXG.Point

    Point to reflect.

  • [board=point.board] Object optional

    Reference to the board

Returns:

JXG.Coords:

Coordinates of the reflected point.

releauxPolygon

(
  • points
  • nr
)
Array

Helper function to create curve which displays a Reuleaux polygons.

Parameters:

  • points Array

    Array of points which should be the vertices of the Reuleaux polygon. Typically, these point list is the array vrtices of a regular polygon.

  • nr Number

    Number of vertices

Returns:

Array:

An array containing the two functions defining the Reuleaux polygon and the two values for the start and the end of the paramtric curve. array may be used as parent array of a {@link JXG.Curve}.

Example:

var A = brd.create('point',[-2,-2]);
                    var B = brd.create('point',[0,1]);
                    var pol = brd.create('regularpolygon',[A,B,3], {withLines:false, fillColor:'none', highlightFillColor:'none', fillOpacity:0.0});
                    var reuleauxTriangle = brd.create('curve', JXG.Math.Geometry.reuleauxPolygon(pol.vertices, 3),
                                         {strokeWidth:6, strokeColor:'#d66d55', fillColor:'#ad5544', highlightFillColor:'#ad5544'});
                    

rotation

(
  • rotpoint
  • point
  • phi
  • [board=point.board]
)
JXG.Coords

Computes the new position of a point which is rotated around a second point (called rotpoint) by the angle phi.

Parameters:

  • rotpoint JXG.Point

    Center of the rotation

  • point JXG.Point

    point to be rotated

  • phi Number

    rotation angle in arc length

  • [board=point.board] JXG.Board optional

    Reference to the board

Returns:

JXG.Coords:

Coordinates of the new position.

signedPolygon

(
  • p
  • [sort=true]
)
Number

Determine the signed area of a non-intersecting polygon. Surveyor's Formula

Parameters:

  • p Array

    An array containing {@link JXG.Point}, {@link JXG.Coords}, and/or arrays.

  • [sort=true] Boolean optional

Returns:

signedTriangle

(
  • p1
  • p2
  • p3
)
Number

Signed triangle area of the three points given.

Returns:

sortVertices

(
  • p
)
Array

Sort list of points counter clockwise starting with the point with the lowest y coordinate.

Parameters:

  • p Array

    An array containing {@link JXG.Point}, {@link JXG.Coords}, and/or arrays.

Returns:

trueAngle

(
  • A
  • B
  • C
)
Number

Calculates the angle (in degrees) defined by the three points A, B, C if you're going from A to C around B counterclockwise.

Parameters:

  • A JXG.Point,Array

    Point or [x,y] array

  • B JXG.Point,Array

    Point or [x,y] array

  • C JXG.Point,Array

    Point or [x,y] array

Returns:

Number:

The angle in degrees.

See also:

  • #rad