This is a collection of procedures and types for computing intersections between two B é zier triangles in R2. The region(s) of intersection (if non-empty) will be curved polygons defined by the B é zier curve segments that form the exterior.
Note
In most of the procedures below both the number of nodes N and the degree d of a B é zier triangle are provided. It is redundant to require both as arguments since
This solves the inverse problem B(s, t) = (x, y) (if it can be solved). Does so by subdividing the triangle until the sub-triangles are sufficiently small, then using Newton's method to narrow in on the pre-image of the point.
This assumes the triangle is "valid", i.e. it has positive Jacobian throughout the unit triangle. (If this were not true, then multiple inputs could map to the same output.)
- param num_nodes
[Input] The number of nodes N in the control net of the B é zier triangle.
- type num_nodes
const int*
- param nodes
[Input] The actual control net of the B é zier triangle as a 2 × N array. This should be laid out in Fortran order, with 2N total values.
- type nodes
const double*
- param degree
[Input] The degree d of the B é zier triangle.
- type degree
const int*
- param x_val
[Input] The x-value of the point being located.
- type x_val
const double*
- param y_val
[Input] The y-value of the point being located.
- type y_val
const double*
- param double* s_val
[Output] The first parameter s of the solution. If (x, y) can't be located on the triangle, then
s_val = -1.0
.- param double* t_val
[Output] The second parameter t of the solution. If (x, y) can't be located on the triangle, then this value is undefined.
Signature:
void BEZ_locate_point_triangle(const int *num_nodes, const double *nodes, const int *degree, const double *x_val, const double *y_val, double *s_val, double *t_val);
This refines a solution to B(s, t) = (x, y) = p using Newton's method. Given a current approximation (sn, tn) for a solution, this produces the updated approximation via
$$\begin{aligned} \left[\begin{array}{c} s_{n + 1} \\ t_{n + 1} \end{array}\right] = \left[\begin{array}{c} s_n \\ t_n \end{array}\right] - DB(s_n, t_n)^{-1} \left(B(s_n, t_n) - p\right). \end{aligned}$$
- param num_nodes
[Input] The number of nodes N in the control net of the B é zier triangle.
- type num_nodes
const int*
- param nodes
[Input] The actual control net of the B é zier triangle as a 2 × N array. This should be laid out in Fortran order, with 2N total values.
- type nodes
const double*
- param degree
[Input] The degree d of the B é zier triangle.
- type degree
const int*
- param x_val
[Input] The x-value of the point p.
- type x_val
const double*
- param y_val
[Input] The y-value of the point p.
- type y_val
const double*
- param s
[Input] The first parameter sn of the current approximation of a solution.
- type s
const double*
- param t
[Input] The second parameter tn of the current approximation of a solution.
- type t
const double*
- param double* updated_s
[Output] The first parameter sn + 1 of the updated approximation.
- param double* updated_t
[Output] The second parameter tn + 1 of the updated approximation.
Signature:
void BEZ_newton_refine_triangle(const int *num_nodes, const double *nodes, const int *degree, const double *x_val, const double *y_val, const double *s, const double *t, double *updated_s, double *updated_t);
Compute the intersection of two B é zier triangles. This will first compute all intersection points between edges of the first and second triangle (nine edge pairs in total). Then, it will classify each point according to which triangle is "interior" at that point. Finally, it will form a loop of intersection points using the classifications until all intersections have been used or discarded.
Tip
If the
status
returned is :cINSUFFICIENT_SPACE
that means either
segment_ends_size
is smaller thannum_intersected
sosegment_ends
needs to be resized to at least as large asnum_intersected
.segments_size
is smaller than the number of segments. The number of segments will be the last index in the list of edge indices:segment_ends[num_intersected - 1]
. In this casesegments
needs to be resized.This means a successful invocation of this procedure may take three attempts. To avoid false starts occurring on a regular basis, keep a static workspace around that will continue to grow as resizing is needed, but will never shrink.
- param num_nodes1
[Input] The number of nodes N1 in the control net of the first B é zier triangle.
- type num_nodes1
const int*
- param nodes1
[Input] The actual control net of the first B é zier triangle as a 2 × N1 array. This should be laid out in Fortran order, with 2N1 total values.
- type nodes1
const double*
- param degree1
[Input] The degree d1 of the first B é zier triangle.
- type degree1
const int*
- param num_nodes2
[Input] The number of nodes N2 in the control net of the second B é zier triangle.
- type num_nodes2
const int*
- param nodes2
[Input] The actual control net of the second B é zier triangle as a 2 × N2 array. This should be laid out in Fortran order, with 2N2 total values.
- type nodes2
const double*
- param degree2
[Input] The degree d2 of the second B é zier triangle.
- type degree1
const int*
- param segment_ends_size
[Input] The size of
segment_ends
, which must be pre-allocated by the caller.- type segment_ends_size
const int*
- param int* segment_ends
[Output] An array (pre-allocated by the caller) of the end indices for each group of segments in
segments
. For example, if the triangles intersect in two distinct curved polygons, the first of which has four sides and the second of which has three, then the first two values insegment_ends
will be[4, 7]
andnum_intersected
will be2
.- param segments_size
[Input] The size of
segments
, which must be pre-allocated by the caller.- type segments_size
const int*
- param CurvedPolygonSegment* segments
[Output] An array (pre-allocated by the caller) of the edge segments that make up the boundary of the curved polygon(s) that form the intersection of the two triangles.
- param int* num_intersected
[Output] The number of curved polygons in the intersection of two triangles.
- param TriangleContained* contained
[Output] Enum indicating if one triangle is fully contained in the other.
- param Status* status
[Output] The status code for the procedure. Will be
- :c
SUCCESS
on success.- :c
INSUFFICIENT_SPACE
ifsegment_ends_size
is smaller thannum_intersected
or ifsegments_size
is smaller than the number of segments.- :c
UNKNOWN
if the intersection points are classified in an unexpected way (e.g. if there is both an ignored corner and a tangent intersection, but no other types).- :c
NO_CONVERGE
if the two curves in an edge pair don't converge to approximately linear after being subdivided 20 times. (This error will occur via :cBEZ_curve_intersections
.)- An integer NC ≥ 64 to indicate that there were NC pairs of candidate segments during edge-edge intersection that had overlapping convex hulls. This is a sign of either round-off error in detecting that the edges are coincident curve segments on the same algebraic curve or that the intersection is a non-simple root. (This error will occur via :c
BEZ_curve_intersections
.)- :c
BAD_MULTIPLICITY
if the two curves in an edge pair have an intersection that doesn't converge to either a simple or double root via Newton's method. (This error will occur via :cBEZ_curve_intersections
.)- :c
EDGE_END
If there is an attempt to add an intersection point with either the s or t-parameter equal to 1 (i.e. if the intersection is at the end of an edge). This should not occur because such intersections are "rotated" to the beginning of the neighboring edge before the boundary of the curved polygon is formed.- :c
SAME_CURVATURE
if the two curves in an edge pair have identical curvature at a tangent intersection.- :c
BAD_INTERIOR
if a curved polygon requires more than 10 sides. This could be due to either a particular complex intersection, a programming error or round-off which causes an infinite loop of intersection points to be added without wrapping around back to the first intersection point.Signature:
void BEZ_triangle_intersections(const int *num_nodes1, const double *nodes1, const int *degree1, const int *num_nodes2, const double *nodes2, const int *degree2, const int *segment_ends_size, int *segment_ends, const int *segments_size, CurvedPolygonSegment *segments, int *num_intersected, TriangleContained *contained, Status *status);