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.
Classes or JavaScript objects defining parametric surfaces should 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 anevaluate
method and may contain anendPoints
,tangent
,bitangent
, and/orgradient
method, as described in the corresponding methods of this class.
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.
Finds an approximate bitangent vector of this surface at the given U and V coordinates.
The implementation in 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 glmath.
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>)
Examples
<caption> The following code is a very simple surface evaluator object. var evaluator = new Surface({ "evaluate":function(u, v) { // Take the U parameter as the X coordinate, // the V parameter as the Y coordinate, and 0 as // the Z coordinate. return [u, v, 0]; } });
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.
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>)
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 glmath.
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 later. 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]; }})
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>)
Finds an approximate tangent vector of this surface at the given U and V coordinates.
The implementation in 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 glmath.
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>)