# Namespace JXG.Math.Clip

↳ JXG.Math.Clip

Defined in: clip.js.

Namespace Summary
Constructor Attributes Constructor Name and Description

Math.Clip namespace definition.
Method Summary
Method Attributes Method Name and Description
<private> <static>
JXG.Math.Clip.det(p1, p2, q)
Determinant of three points in the Euclidean plane.
<static>
JXG.Math.Clip.difference(subject, clip, board)
Difference of two closed paths, i.e.
<private> <static>
Add pointers to an array S such that it is a circular doubly-linked list.
<private> <static>
JXG.Math.Clip.findIntersections(S, C, board)
Find all intersections between two paths.
<static>
JXG.Math.Clip.greinerHormann(subject, clip, clip_type, board)
Determine the intersection, union or difference of two closed paths.
<private> <static>
JXG.Math.Clip.handleEmptyIntersection(S, C, clip_type)
Handle cases when there are no intersection points of the two paths.
<static>
JXG.Math.Clip.intersection(subject, clip, board)
Intersection of two closed paths.
<private> <static>
JXG.Math.Clip.isEmptyCase(S, C, clip_type, pathX, pathY)
Handle path clipping if one of the two paths is empty.
<private> <static>
JXG.Math.Clip.markEntryExit(path1, path2)
Mark the intersection vertices of path1 as entry points or as exit points in respect to path2.
<private> <static>
JXG.Math.Clip.sortIntersections(P_crossings)
Sort the intersection points into their path.
<private> <static>
JXG.Math.Clip.tracing(S, S_intersect, clip_type)
Tracing phase of the Greiner-Hormann algorithm, see Greiner, Günther; Kai Hormann (1998).
<static>
JXG.Math.Clip.union(subject, clip, board)
Union of two closed paths.
<private> <static>
JXG.Math.Clip.Vertex(coords, i, alpha, path, pathname)
JavaScript object containing the intersection of two paths.
<static>
JXG.Math.Clip.windingNumber(usrCoords, path)
Winding number of a point in respect to a polygon path.
Namespace Detail
JXG.Math.Clip
Math.Clip namespace definition. This namespace contains algorithms for Boolean operations on paths, i.e. intersection, union and difference of paths. Base is the Greiner-Hormann algorithm.
Method Detail
<private> <static> {Number} JXG.Math.Clip.det(p1, p2, q)
Determinant of three points in the Euclidean plane. Zero, if the points are collinear. Used to determine of a point q is left or right to a segment defined by points p1 and p2.
Parameters:
{Array} p1
Coordinates of the first point of the segment. Array of length 3. First coordinate is equal to 1.
{Array} p2
Coordinates of the second point of the segment. Array of length 3. First coordinate is equal to 1.
{Array} q
Coordinates of the point. Array of length 3. First coordinate is equal to 1.
Returns:
{Number} Signed area of the triangle formed by these three points.

<static> {Array} JXG.Math.Clip.difference(subject, clip, board)
Difference of two closed paths, i.e. path1 minus path2. The paths could be JSXGraph elements circle, curve, or polygon. Computed by the Greiner-Hormann algorithm.
Parameters:
subject
First closed path.
clip
Second closed path.
board
JSXGraph board object. It is needed to convert between user coordinates and screen coordinates.
Returns:
{Array} Array consisting of two arrays containing the x-coordinates and the y-coordinates of the resulting path.
See:
JXG.Math.Clip#greinerHormann
JXG.Math.Clip#intersection
JXG.Math.Clip#union
Examples:
```    var curve1 = board.create('polygon', [[-4, 4], [4, 4], [0, -1]],
{strokeColor: 'blue', fillColor: 'none'});

var curve2 = board.create('curve', [
[-1, 1, 0, -1],
[1, 1, 3, 1]
],
{strokeColor: 'black', fillColor: 'none', fillOpacity: 0.8});

var clip_path = board.create('curve', [[], []], {strokeWidth: 3, fillColor: 'yellow', fillOpacity: 0.3});
clip_path.updateDataArray = function() {
var a = JXG.Math.Clip.difference(curve1, curve2, this.board);
this.dataX = a;
this.dataY = a;
};

board.update();

```

Add pointers to an array S such that it is a circular doubly-linked list.
Parameters:
{Array} S
Array
Returns:
{Array} return the array S

<private> <static> {Array} JXG.Math.Clip.findIntersections(S, C, board)
Find all intersections between two paths.
Parameters:
{Array} S
Subject path
{Array} C
Clip path
board
JSXGraph board object. It is needed to convert between user coordinates and screen coordinates.
Returns:
{Array} Array containing two arrays. The first array contains the intersection vertices of the subject path and the second array contains the intersection vertices of the clip path.
See:
JXG.Clip#Vertex

<static> {Array} JXG.Math.Clip.greinerHormann(subject, clip, clip_type, board)
Determine the intersection, union or difference of two closed paths. This is an implementation of the Greiner-Hormann algorithm, see Greiner, Günther; Kai Hormann (1998). "Efficient clipping of arbitrary polygons". ACM Transactions on Graphics. 17 (2): 71–83.
Parameters:
subject
First closed path, usually called 'subject'.
clip
Second closed path, usually called 'clip'.
{String} clip_type
Determines the type of boolean operation on the two paths. Possible values are 'intersection', 'union', or 'difference'.
board
JSXGraph board object. It is needed to convert between user coordinates and screen coordinates.
Returns:
{Array} Array consisting of two arrays containing the x-coordinates and the y-coordinates of the resulting path.
See:
JXG.Math.Clip#intersection
JXG.Math.Clip#union
JXG.Math.Clip#difference
Examples:
```    var curve1 = board.create('curve', [
[-3, 3, 0, -3],
[3, 3, 0, 3]
],
{strokeColor: 'black'});

var curve2 = board.create('curve', [
[-4, 4, 0, -4],
[2, 2, 4, 2]
],
{strokeColor: 'blue'});

var clip_path = board.create('curve', [[], []], {strokeWidth: 3, fillColor: 'yellow', fillOpacity: 0.6});
clip_path.updateDataArray = function() {
var a = JXG.Math.Clip.greinerHormann(curve2, curve1, 'intersection', this.board);

this.dataX = a;
this.dataY = a;
};

board.update();

```

```    var curve1 = board.create('curve', [
[-3, 3, 0, -3],
[3, 3, 0, 3]
],
{strokeColor: 'black', fillColor: 'none', fillOpacity: 0.8});

var curve2 = board.create('polygon', [[3, 4], [-4, 0], [-4, 4]],
{strokeColor: 'blue', fillColor: 'none'});

var clip_path = board.create('curve', [[], []], {strokeWidth: 3, fillColor: 'yellow', fillOpacity: 0.6});
clip_path.updateDataArray = function() {
var a = JXG.Math.Clip.greinerHormann(curve1, curve2, 'union', this.board);
this.dataX = a;
this.dataY = a;
};

board.update();

```

```    var curve1 = board.create('curve', [
[-4, 4, 0, -4],
[4, 4, -2, 4]
],
{strokeColor: 'black', fillColor: 'none', fillOpacity: 0.8});

var curve2 = board.create('circle', [[0, 0], [0, -2]],
{strokeColor: 'blue', strokeWidth: 1, fillColor: 'red', fixed: true, fillOpacity: 0.3,
center: {visible: true, size: 5}, point2: {size: 5}});

var clip_path = board.create('curve', [[], []], {strokeWidth: 3, fillColor: 'yellow', fillOpacity: 0.6});
clip_path.updateDataArray = function() {
var a = JXG.Math.Clip.greinerHormann(curve1, curve2, 'difference', this.board);

this.dataX = a;
this.dataY = a;
};

board.update();

```

<private> <static> {Array} JXG.Math.Clip.handleEmptyIntersection(S, C, clip_type)
Handle cases when there are no intersection points of the two paths. This is the case if the paths are disjoint or one is contained in the other.
Parameters:
{Array} S
First path, array of JXG.Coords
{Array} C
Second path, array of JXG.Coords
{String} clip_type
Type of Boolean operation: 'intersection', 'union', 'differrence'.
Returns:
{Array} Array consisting of two arrays containing the x-coordinates and the y-coordinates of the resulting path.

<static> {Array} JXG.Math.Clip.intersection(subject, clip, board)
Intersection of two closed paths. The paths could be JSXGraph elements circle, curve, or polygon. Computed by the Greiner-Hormann algorithm.
Parameters:
subject
First closed path.
clip
Second closed path.
board
JSXGraph board object. It is needed to convert between user coordinates and screen coordinates.
Returns:
{Array} Array consisting of two arrays containing the x-coordinates and the y-coordinates of the resulting path.
See:
JXG.Math.Clip#greinerHormann
JXG.Math.Clip#union
JXG.Math.Clip#difference
Examples:
```var p = [];
p.push(board.create('point', [0, -5]));
p.push(board.create('point', [-5, 0]));
p.push(board.create('point', [-3, 3]));

var curve1 = board.create('ellipse', p,
{strokeColor: 'black'});

var curve2 = board.create('curve', [function(phi){return 4 * Math.cos(2*phi); },
[0, 0],
0, 2 * Math.PI],
{curveType:'polar', strokeColor: 'blue', strokewidth:1});

var clip_path = board.create('curve', [[], []], {strokeWidth: 3, fillColor: 'yellow', fillOpacity: 0.3});
clip_path.updateDataArray = function() {
var a = JXG.Math.Clip.intersection(curve2, curve1, this.board);

this.dataX = a;
this.dataY = a;
};

board.update();

```

<private> <static> {Boolean} JXG.Math.Clip.isEmptyCase(S, C, clip_type, pathX, pathY)
Handle path clipping if one of the two paths is empty.
Parameters:
{Array} S
First path, array of JXG.Coords
{Array} C
Second path, array of JXG.Coords
{String} clip_type
Type of Boolean operation: 'intersection', 'union', 'differrence'.
{Array} pathX
Array of x-coordinates of the resulting path
{Array} pathY
Array of y-coordinates of the resulting path
Returns:
{Boolean} true, if one of the input paths is empty, false otherwise.

<private> <static> JXG.Math.Clip.markEntryExit(path1, path2)
Mark the intersection vertices of path1 as entry points or as exit points in respect to path2. This is the simple algorithm as in Greiner, Günther; Kai Hormann (1998). "Efficient clipping of arbitrary polygons". ACM Transactions on Graphics. 17 (2): 71–83
Parameters:
{Array} path1
First path
{Array} path2
Second path

<private> <static> {Array} JXG.Math.Clip.sortIntersections(P_crossings)
Sort the intersection points into their path.
Parameters:
{Array} P_crossings
Array of arrays. Each array contains the intersections of the path with one segment of the other path.
Returns:
{Array} Array of intersection points ordered by first occurrence in the path.

<private> <static> {Array} JXG.Math.Clip.tracing(S, S_intersect, clip_type)
Tracing phase of the Greiner-Hormann algorithm, see Greiner, Günther; Kai Hormann (1998). "Efficient clipping of arbitrary polygons". ACM Transactions on Graphics. 17 (2): 71–83 Boolean operations on polygons are distinguished: 'intersection', 'union', 'difference'.
Parameters:
{Array} S
Subject path
{Array} S_intersect
Array containing the intersection vertices of the subject path
{String} clip_type
contains the Boolean operation: 'intersection', 'union', or 'difference'
Returns:
{Array} Array consisting of two arrays containing the x-coordinates and the y-coordintaes of the resulting path.

<static> {Array} JXG.Math.Clip.union(subject, clip, board)
Union of two closed paths. The paths could be JSXGraph elements circle, curve, or polygon. Computed by the Greiner-Hormann algorithm.
Parameters:
subject
First closed path.
clip
Second closed path.
board
JSXGraph board object. It is needed to convert between user coordinates and screen coordinates.
Returns:
{Array} Array consisting of two arrays containing the x-coordinates and the y-coordinates of the resulting path.
See:
JXG.Math.Clip#greinerHormann
JXG.Math.Clip#intersection
JXG.Math.Clip#difference
Examples:
```    var curve1 = board.create('curve', [
[-3, 3, 0, -3],
[3, 3, 0, 3]
],
{strokeColor: 'black'});

var curve2 = board.create('polygon', [[3, 4], [-4, 0], [-4, 4]],
{strokeColor: 'blue', fillColor: 'none'});

var clip_path = board.create('curve', [[], []], {strokeWidth: 3, fillColor: 'yellow', fillOpacity: 0.3});
clip_path.updateDataArray = function() {
var a = JXG.Math.Clip.union(curve1, curve2, this.board);
this.dataX = a;
this.dataY = a;
};

board.update();

```

<private> <static> JXG.Math.Clip.Vertex(coords, i, alpha, path, pathname)
JavaScript object containing the intersection of two paths. Every intersection point is on one path, but comes with a neighbour point having the same coordinates and being on the other path. The intersection point is inserted into the doubly linked list of the path.
Parameters:
coords
JSXGraph Coords object conatining the coordinates of the intersection
{Number} i
Number of the segment of the subject path (first path) containing the intersection.
{Number} alpha
The intersection is a p_1 + alpha*(p_2 - p_1), where p_1 and p_2 are the end points of the i-th segment.
{Array} path
Pointer to the path containing the intersection point
{String} pathname
Name of the path: 'S' or 'C'.

<static> {Number} JXG.Math.Clip.windingNumber(usrCoords, path)
Winding number of a point in respect to a polygon path. The point is regarded outside if the winding number is zero, inside otherwise. The algorithm tries to find degenerate cases, i.e. if the point is on the path. This is regarded as "outside". If the point is a vertex of the path, it is regarded as "inside". Implementation of algorithm 7 from "The point in polygon problem for arbitrary polygons" by Kai Hormann and Alexander Agathos, Computational Geometry, Volume 20, Issue 3, November 2001, Pages 131-144.
Parameters:
{Array} usrCoords
Homogenous coordinates of the point
{Array} path
Array of JXG.Coords determining a path, i.e. the vertices of the polygon.
Returns:
{Number} Winding number of the point. The point is regarded outside if the winding number is zero, inside otherwise.

Documentation generated by JsDoc Toolkit 2.4.0 on Tue Jun 02 2020 21:22:44 GMT+0200 (Mitteleuropäische Sommerzeit)