# 1.13 NURBS Curve Support in Oracle Spatial and Graph

Spatial and Graph supports non-uniform rational B-spline (NURBS) curve geometries. NURBS curves allow representation of free-form shapes with arbitrary shapes. NURBS representation allows control over the shape of the curve because control points and knots guide the shape of the curve, and they allow complex shapes to be represented with little data.

Support for NURBS curves in Spatial and Graph includes the following:

• WKT/WKB and GML functions for loading and storing of NURBS curve geometries in Oracle Spatial and Graph.

• Validation of NURBS curve geometries.

• Spatial indexing of NURBS curve geometries along with the SDO_FILTER, SDO_RELATE, and other operators. Spatial operators use an approximation of the curve for computation.

A NURBS representation requires specification of the control points and the basis functions. The basis functions, in turn, are defined using the knot vector and the degree of the curve. The control points are used to determine the shape of the NURBS curve. The knot vector does not directly control the shape of the curve, but is used to control the exact placement of end points. The knot vector is also used to create curves with kinks and corners. Non-uniform knot vectors are used for manipulating the curve.

To represent a NURBS curve, the following data must be stored: the control points, the knot vector, and the degree of the curve. The set of control points can be represented in either the Euclidean form as `(x, y, z, w)` where `w` represents the weight of the control point or in the homogeneous form as `(wx, wy, wz, w)`. If `wi`=1 for all `i`, the curve is non-rational. The control points are specified in the weighted Euclidean form. Basis functions can be uniform or non-uniform based on the knot vector. A non-uniform knot vector is useful for placement of end points and creating kinks or corners. A normalized knot vector must be specified, that is, the first knot in the knot vector must be zero and the last knot in the knot vector must be one. It is also required that the knot vector is "clamped" at the end points. This requirement is enforced by ensuring that the first `d`+1 values in the knot vector are all zeros and the last `d`+1 values are all ones, where `d` represents the degree of the NURBS curve.

The implementation of NURBS curves in Oracle Spatial and Graph follows the SQL/MM standards. The SQL/MM standards for NURBS curves are used to represent splines, polynomial splines, cubic splines, B-splines, and Bezier curves. In Oracle Spatial and Graph, the SDO_GEOMETRY object type is used for NURBS representation. NURBS curves can be included in the Line, Multiline, and Collection type geometry objects. In these geometries, the simple line string and compound line string type elements can contain NURBS.

For compound line strings containing at least one NURBS segment, the last point of the previous segment is the same as the "clamped" first control point of a NURBS segment, and the last "clamped" control point of a NURBS segment is the same as the first point of the next segment. That is, the vertices will be repeated.

For geometry elements with element type value 2 representing a line string, the interpretation value of 3 is used to represent a NURBS curve; interpretation values of 1 and 2 represent linear segments and arcs. The SDO_ELEM_INFO_ARRAY for a NURBS curve is stored as (offset, 2, 3), which represents the offset, element type, and the interpretation value.

The SDO_ORDINATE_ARRAY stores the degree of the curve `d`, the set of `m` control points and a knot vector of size `n`. So, the ordinate array is stored as a sequence of values `(d, m, x1, y1, z1, w1…. xm, ym, zm, wm, n, k1….kn)`. The control points are stored in the Euclidean form as specified in the SQL/MM standards. Note that for a NURBS curve the number of knots is equal to the sum of the degree, the number of control points, and 1. Therefore, `n=d+m+1`, an equation which is useful for validating NURBS curve geometries.

The following considerations apply to defining a NURBS curve:

• The degree of the curve should be greater than 1, because a curve of degree 1 represents polylines.

• The number of control points must be greater than or equal to 3, and must be greater than the degree.

• The number of knots must be equal to the (number of control points + degree + 1).

• The weight component of each control point must be positive.

• Control points are represented in "weighted Euclidean" form `[wx, wy, (wz), w]`.

• Knot values should be specified in non-decreasing order, and the knot vector must be a normalized knot vector `[0, .. ……, 1]`.

• If `d` is the degree of the curve, there must be `d`+1 consecutive equal knots at the beginning of the curve (value 0) and `d`+1 consecutive equal knots at the end of the curve (value 1). This is to ensure that the curve is clamped at the end points.

• If `d` is the degree of the curve, there must not be more than `d` consecutive equal knots except at the beginning or end of the curve where `d`+1 knots must be present.

Be sure to validate geometries with NURBS segments before creating the spatial index or performing any spatial operations on them. (This recommendation applies to all geometry types, NURBS or otherwise.)

For examples that specify NURBS curve geometries, see NURBS Curve.

To get a line string geometry that is an approximation of an input NURBS curve geometry, use the SDO_UTIL.GETNURBSAPPROX function.