# H3DU.Surface

### H3DU.Surface(surface)

A surface evaluator object for a parametric surface.

A parametric surface is a surface whose points are based on a parametric surface function. A surface function takes two numbers (U and V) and returns a point (in 1, 2, 3 or more dimensions, but usually 2 or 3) that lies on the surface. For example, in 3 dimensions, a surface function has the following form:

**F**(u, v) = [ x(u, v), y(u, v), z(u, v) ]

where x(u, v) returns an X coordinate, y(u, v) a Y coordinate, and z(u, v) returns a Z coordinate.

Specialized surfaces should subclass this class and implement
the `evaluate`

method and, optionally, the other methods mentioned in the "surface" parameter below.

#### Parameters

`surface`

(Type: Object)

A**surface evaluator object**, which is an object that must contain an`evaluate`

method and may contain an`endPoints`

,`tangent`

,`bitangent`

, and/or`gradient`

method, as described in the corresponding methods of this class.

#### Example

The following example creates a surface evaluator object for a parametric surface. 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:

**c**(u, v) = (-sin(v)*cos(u)*sin(u), -sin(v)*sin(u)*sin(u), 0)

The result is the gradient, which will be normal to the surface.

var surface=new H3DU.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]; }})

### Methods

- bitangent

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

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

Finds the position of this surface at the given U and V coordinates. - 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 an approximate tangent vector of this surface at the given U and V coordinates.

### H3DU.Surface#bitangent(u, v)

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

The implementation in H3DU.Surface calls the evaluator's `bitangent`

method if it implements it; otherwise, does a numerical differentiation
with respect to the V axis using the `evaluate`

method.

The **bitangent vector** is the vector pointing in the direction of the V axis, or alternatively,
the partial derivative of the `evaluate`

method with respect to `v`

. The bitangent vector 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 bitangent vector. It should have at least as many elements as the number of dimensions of the underlying surface. (Type: Array.<number>)

### H3DU.Surface#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.

### H3DU.Surface#evaluate(u, v)

Finds the position of this surface at the given U and V coordinates.

#### 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 position. It should have at least as many elements as the number of dimensions of the underlying surface. (Type: Array.<number>)

### H3DU.Surface#gradient(u, v)

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

The implementation in H3DU.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 three-dimensional surface).

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>)

### H3DU.Surface#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>)

### H3DU.Surface#tangent(u, v)

Finds an approximate tangent vector of this surface at the given U and V coordinates.
The implementation in H3DU.Surface calls the evaluator's `tangent`

method if it implements it; otherwise, does a numerical differentiation
with respect to the U axis using the `evaluate`

method.

The **tangent vector** is the vector pointing in the direction of the U axis,
or alternatively, the partial derivative of the `evaluate`

method with respect to `u`

.
The tangent vector 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 tangent vector. It should have at least as many elements as the number of dimensions of the underlying surface. (Type: Array.<number>)