Namespace JXG.Math.Clip
↳ JXG.Math.Clip
Defined in: clip.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Math.Clip namespace definition.
|
Method Attributes | Method Name and Description |
---|---|
<private> <static> |
JXG.Math.Clip._getPath(obj, board)
Create path from all sorts of input elements to greinerHormann().
|
<private> <static> |
JXG.Math.Clip._handleFullyDegenerateCase(S, C, board)
Handle the case that all vertices of one path are contained
in the other path.
|
<private> <static> |
JXG.Math.Clip._isCrossing(P, isBackward)
|
<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> |
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.makeDoublyLinkedList(S)
Add pointers to an array S such that it is a circular doubly-linked list.
|
<private> <static> |
JXG.Math.Clip.markEntryExit(path1, path2, starters)
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, type)
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.
|
- Parameters:
- {Object} obj
- Maybe curve, arc, sector, circle, polygon, array of points, array of JXG.Coords, array of coordinate pairs.
- {JXG.Board} board
- JSXGraph board object. It is needed to convert between user coordinates and screen coordinates.
- Returns:
- {Array} Array of JXG.Coords elements containing a path.
- See:
- JXG.Math.Clip#greinerHormann
- Parameters:
- {Array} S
- Subject path
- {Array} C
- Clip path
- {JXG.board} board
- JSXGraph board object. It is needed to convert between user coordinates and screen coordinates.
- Parameters:
- {Array} P
- {Boolean} isBackward
- Returns:
- {Boolean} True, if the node is an intersection and is of type 'X'
- 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.
- Parameters:
- {JXG.Circle|JXG.Curve|JXG.Polygon} subject
- First closed path.
- {JXG.Circle|JXG.Curve|JXG.Polygon} clip
- Second closed path.
- {JXG.Board} 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[0]; this.dataY = a[1]; }; board.update();
- Parameters:
- {Array} S
- Subject path
- {Array} C
- Clip path
- {JXG.Board} 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
This is an implementation of the Greiner-Hormann algorithm, see Günther Greiner and Kai Hormann (1998). "Efficient clipping of arbitrary polygons". ACM Transactions on Graphics. 17 (2): 71–83. and Erich, L. Foster, and Kai Hormann, Kai, and Romeo Traaian Popa (2019), "Clipping simple polygons with degenerate intersections", Computers & Graphics:X, 2.
It is assumed that the pathes are closed, whereby it does not matter if the last point indeed equals the first point. In contrast to the original Greiner-Hormann algorithm, this algorithm can cope with many degenerate cases. A degenerate case is a vertext of one path which is contained in the other path.
Problematic are:
- degenerate cases where one path additionally has self-intersections
- differences with one path having self-intersections.
- Parameters:
- {JXG.Circle|JXG.Curve|JXG.Polygon} subject
- First closed path, usually called 'subject'. Maybe curve, arc, sector, circle, polygon, array of points, array of JXG.Coords, array of coordinate pairs.
- {JXG.Circle|JXG.Curve|JXG.Polygon} clip
- Second closed path, usually called 'clip'. Maybe curve, arc, sector, circle, polygon, array of points, array of JXG.Coords, array of coordinate pairs.
- {String} clip_type
- Determines the type of boolean operation on the two paths. Possible values are 'intersection', 'union', or 'difference'.
- {JXG.Board} 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[0]; this.dataY = a[1]; }; 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[0]; this.dataY = a[1]; }; 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[0]; this.dataY = a[1]; }; board.update();
var clip_path = board.create('curve', [[], []], {strokeWidth: 1, fillColor: 'yellow', fillOpacity: 0.6}); clip_path.updateDataArray = function() { var bbox = this.board.getBoundingBox(), canvas, triangle; canvas = [[bbox[0], bbox[1]], // ul [bbox[0], bbox[3]], // ll [bbox[2], bbox[3]], // lr [bbox[2], bbox[1]], // ur [bbox[0], bbox[1]]] // ul triangle = [[-1,1], [1,1], [0,-1], [-1,1]]; var a = JXG.Math.Clip.greinerHormann(canvas, triangle, 'difference', this.board); this.dataX = a[0]; this.dataY = a[1]; };
- 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.
- Parameters:
- {JXG.Circle|JXG.Curve|JXG.Polygon} subject
- First closed path.
- {JXG.Circle|JXG.Curve|JXG.Polygon} clip
- Second closed path.
- {JXG.Board} 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[0]; this.dataY = a[1]; }; board.update();
- 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.
- Parameters:
- {Array} S
- Array
- Returns:
- {Array} return containing the starter indices of each component.
- Parameters:
- {Array} path1
- First path
- {Array} path2
- Second path
- starters
- 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.
- 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.
- Parameters:
- {JXG.Circle|JXG.Curve|JXG.Polygon} subject
- First closed path.
- {JXG.Circle|JXG.Curve|JXG.Polygon} clip
- Second closed path.
- {JXG.Board} 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[0]; this.dataY = a[1]; }; board.update();
- Parameters:
- {JXG.Coords} 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'.
- type
- Parameters:
- {Array} usrCoords
- Homogenous coordinates of the point
- {Array} path
- Array of points determining a path, i.e. the vertices of the polygon. The array elements do not have to be full points, but have to have a subobject "coords".
- Returns:
- {Number} Winding number of the point. The point is regarded outside if the winding number is zero, inside otherwise.