# BSplineSurface

### new BSplineSurface(controlPoints, knotsU, knotsV, [bits])

**Augments:** Surface

A surface evaluator object for a B-spline (basis spline) surface, whose edges are made up of B-spline curves. For more on B-spline curves, see the constructor for BSplineCurve.

#### Parameters

`controlPoints`

(Type: Array.<Array.<Array.<number>>>)

An array of control point arrays, which in turn contain a number of control points. Each control point is an array with the same length as the other control points. It is assumed that:- The length of this parameter is the number of control points in each row of the V axis.
- The length of the first control point array is the number of control points in each column of the U axis.
- The first control point's length represents the size of all the control points.

`knotsU`

(Type: Array.<number>)

Knot vector of the surface, along the U axis. For more information, see BSplineCurve.`knotsV`

(Type: Array.<number>)

Knot vector of the surface, along the V axis.`bits`

(Type: number) (optional)

Bits for defining input and controlling output. Zero or more of BSplineCurve.DIVIDE_BIT. If null, undefined, or omitted, no bits are set.

#### Examples

Together with 'convertToHomogen' given in the BSplineCurve documentation, the following function can be used to convert an array of arrays of control points, each consisting of conventional coordinates and a weight, to homogeneous coordinates. For example, the single-control point array '[[[2, 3, 4, 0.1]]]' becomes '[[[0.2, 0.3, 0.4, 0.1]]]'; the return value can then be used in the BSplineSurface constructor to create a rational B-Spline surface.

function convertSurfaceToHomogen(cp) { var ret = []; for(var i = 0; i < cp.length; i++) { ret.push(convertToHomogen(cp[i])); } return ret; };

### Methods

- bitangent

Finds the bitangent vector at the given point on the surface. - clamped

Creates a B-spline surface with uniform knots, except that the surface's edges lie on the edges of the control point array. - endPoints

Returns the starting and ending U and V coordinates of this surface. - evaluate

Evaluates the surface function based on a point in a B-spline surface. - fromBezierSurface

Creates a B-spline surface from the control points of a Bézier surface. - getControlPoints

Gets a reference to the array of control point arrays used in this surface object. - getKnots

Gets a reference to the array of knot vectors used in this curve object. - gradient

Finds an approximate gradient vector of this surface at the given U and V coordinates. - normal

Convenience method for finding an approximate normal vector of this surface at the given U and V coordinates. - tangent

Finds the tangent vector at the given point on the surface. - uniform

Creates a B-spline surface with uniform knots.

### BSplineSurface#bitangent(u, v)

Finds the bitangent vector at the given point on the surface.

#### Parameters

`u`

(Type: number)

U coordinate of the surface to evaluate.`v`

(Type: number)

V coordinate of the surface to evaluate.

#### Return Value

An array giving the bitangent vector. It will have as many elements as a control point (or one fewer if DIVIDE_BIT is set), as specified in the constructor. (Type: Array.<number>)

### (static) BSplineSurface.clamped(controlPoints, [degreeU], [degreeV], [bits])

Creates a B-spline surface with uniform knots, except that the surface's edges lie on the edges of the control point array.

#### Parameters

`controlPoints`

(Type: Array.<Array.<Array.<number>>>)

Array of control point arrays as specified in the BSplineSurface constructor.`degreeU`

(Type: number) (optional)

Degree of the B-spline surface along the U axis. For example, 3 means a degree-3 (cubic) curve. If null, undefined, or omitted, the default is 3.`degreeV`

(Type: number) (optional)

Degree of the B-spline surface along the V axis If null, undefined, or omitted, the default is 3.`bits`

(Type: number) (optional)

Bits as specified in the BSplineSurface constructor.

#### Return Value

Return value. The first knot of the curve will be 0 and the last knot will be 1. (Type: BSplineSurface)

### BSplineSurface#endPoints()

Returns the starting and ending U and V coordinates of this surface.
This method calls the evaluator's `endPoints`

method if it implements it; otherwise, returns `[0, 1, 0, 1]`

#### Return Value

A four-element array. The first and second
elements are the starting and ending U coordinates, respectively, of the surface, and the third
and fourth elements are its starting and ending V coordinates.
Returns `[0, 1, 0, 1]`

if the evaluator doesn't implement an `endPoints`

method.

### BSplineSurface#evaluate(u, v)

Evaluates the surface function based on a point in a B-spline surface.

#### Parameters

`u`

(Type: number)

U coordinate of the surface to evaluate.`v`

(Type: number)

V coordinate of the surface to evaluate.

#### Return Value

An array of the result of the evaluation. It will have as many elements as a control point (or one fewer if DIVIDE_BIT is set), as specified in the constructor. (Type: Array.<number>)

### (static) BSplineSurface.fromBezierSurface(controlPoints, [bits])

Creates a B-spline surface from the control points of a Bézier surface.

#### Parameters

`controlPoints`

(Type: Array.<Array.<Array.<number>>>)

An array of control point arrays, which in turn contain a number of control points. Each control point is an array with the same length as the other control points. It is assumed that:- The length of this parameter minus 1 represents the degree of the Bézier surface along the V axis. For example, a degree-3 (cubic) surface along the V axis contains 4 control points, one in each control point array. A degree of 1 on both the U and V axes results in a flat surface.
- The length of the first control point array minus 1 represents the degree of the Bézier surface along the U axis.
- The number of elements in the first control point represents the number of elements in all the control points.

`bits`

(Type: number) (optional)

Bits as specified in the BSplineSurface constructor.

#### Return Value

Return value. (Type: BSplineSurface)

### BSplineSurface#getControlPoints()

Gets a reference to the array of control point arrays used in this surface object.

#### Return Value

An object described in the constructor to BSplineCurve. (Type: Array.<Array.<number>>)

### BSplineSurface#getKnots()

Gets a reference to the array of knot vectors used in this curve object.

#### Return Value

An object described in the constructor to BSplineSurface. (Type: Array.<Array.<number>>)

### BSplineSurface#gradient(u, v)

Finds an approximate gradient vector of this surface at the given U and V coordinates.

The implementation in Surface calls the evaluator's `gradient`

method if it implements it; otherwise uses the surface's tangent and bitangent vectors to implement the gradient
(however, this approach is generally only meaningful for a surface in three-dimensional space).

The **gradient** is a vector pointing up and away from the surface.
If the evaluator describes a regular three-dimensional surface (usually
a continuous, unbroken surface such as a sphere, an open
cylinder, or a disk rotated in three dimensions), this can be the cross product
of the tangent vector
and bitangent vector,
in that order. The gradient returned by this method *should not* be "normalized" to a unit vector.

#### Parameters

`u`

(Type: number)

U coordinate of a point on the surface.`v`

(Type: number)

V coordinate of a point on the surface.

#### Return Value

An array describing a gradient vector. It should have at least as many elements as the number of dimensions of the underlying surface. (Type: Array.<number>)

#### Examples

The following example is a surface evaluator object for a parametric surface with a gradient method. To illustrate how the gradient method is derived from the vector calculation method, that method is also given below. To derive the normal calculation, first look at the vector function:

**F**(u, v) = (cos(u), sin(u), sin(u)*cos(v))

Then, find the partial derivatives with respect to *u* and to *v*:

∂**F**/∂*u* = (-sin(u), cos(u), cos(u)*cos(v))

∂**F**/∂*v* = (0, 0, -sin(v)*sin(u))

Next, take their cross product:

**∇F**(u, v) = (-sin(v)*cos(u)*sin(u), -sin(v)*sin(u)*sin(u), 0)

The result is the gradient, which will point up and away from the surface.

var surface=new Surface({"evaluate":function(u,v) { "use strict"; return [Math.cos(u),Math.sin(u),Math.sin(u)*Math.cos(v)]; }, "gradient":function(u,v) { "use strict"; return [ Math.cos(u)*-Math.sin(v)*Math.sin(u), Math.sin(u)*-Math.sin(v)*Math.sin(u), 0]; }})

### BSplineSurface#normal(u, v)

Convenience method for finding an approximate normal vector of this surface at the given U and V coordinates.
The **normal vector** is the same as the gradient vector, but "normalized" to a unit vector.

#### Parameters

`u`

(Type: number)

U coordinate of a point on the surface.`v`

(Type: number)

V coordinate of a point on the surface.

#### Return Value

An array describing a normal vector. It should have at least as many elements as the number of dimensions of the underlying surface. (Type: Array.<number>)

### BSplineSurface#tangent(u, v)

Finds the tangent vector at the given point on the surface.

#### Parameters

`u`

(Type: number)

U coordinate of the surface to evaluate.`v`

(Type: number)

V coordinate of the surface to evaluate.

#### Return Value

An array giving the tangent vector. It will have as many elements as a control point (or one fewer if DIVIDE_BIT is set), as specified in the constructor. (Type: Array.<number>)

### (static) BSplineSurface.uniform(controlPoints, [degreeU], [degreeV], [bits])

Creates a B-spline surface with uniform knots.

#### Parameters

`controlPoints`

(Type: Array.<Array.<Array.<number>>>)

Array of control point arrays as specified in the BSplineSurface constructor.`degreeU`

(Type: number) (optional)

Degree of the B-spline surface along the U axis. For example, 3 means a degree-3 (cubic) curve. If null, undefined, or omitted, the default is 3.`degreeV`

(Type: number) (optional)

Degree of the B-spline surface along the V axis If null, undefined, or omitted, the default is 3.`bits`

(Type: number) (optional)

Bits as specified in the BSplineSurface constructor.

#### Return Value

Return value. The first knot of the curve will be 0 and the last knot will be 1. (Type: BSplineSurface)