33. nurbs — Using NURBS in pyFormex.

Using NURBS in pyFormex.

The nurbs module defines functions and classes to manipulate NURBS curves and surface in pyFormex.

Classes defined in module nurbs

class nurbs.Coords4

A collection of points represented by their homogeneous coordinates.

While most of the pyFormex implementation is based on the 3D Cartesian coordinates class Coords, some applications may benefit from using homogeneous coordinates. The class Coords4 provides some basic functions and conversion to and from cartesian coordinates. Through the conversion, all other pyFormex functions, such as transformations, are available.

Coords4 is implemented as a float type numpy.ndarray whose last axis has a length equal to 4. Each set of 4 values (x,y,z,w) along the last axis represents a single point in 3D space. The cartesian coordinates of the point are obtained by dividing the first three values by the fourth: (x/w, y/w, z/w). A zero w-value represents a point at infinity. Converting such points to Coords will result in Inf or NaN values in the resulting object.

The float datatype is only checked at creation time. It is the responsibility of the user to keep this consistent throughout the lifetime of the object.

Just like Coords, the class Coords4 is derived from numpy.ndarray.

Parameters

data : array_like
If specified, data should evaluate to an array of floats, with the length of its last axis not larger than 4. When equal to four, each tuple along the last axis represents a ingle point in homogeneous coordinates. If smaller than four, the last axis will be expanded to four by adding values zero in the second and third position and values 1 in the last position. If no data are given, a single point (0.,0.,0.) will be created.
w : array_like
If specified, the w values are used to denormalize the homogeneous data such that the last component becomes w.
dtyp : data-type
The datatype to be used. It not specified, the datatype of data is used, or the default Float (which is equivalent to numpy.float32).
copy : boolean
If True, the data are copied. By default, the original data are used if possible, e.g. if a correctly shaped and typed numpy.ndarray is specified.

Methods

normalize()

Normalize the homogeneous coordinates.

Two sets of homogeneous coordinates that differ only by a multiplicative constant refer to the same points in cartesian space. Normalization of the coordinates is a way to make the representation of a single point unique. Normalization is done so that the last component (w) is equal to 1.

The normalization of the coordinates is done in place.

Warning

Normalizing points at infinity will result in Inf or NaN values.

deNormalize(w)

Denormalizes the homogeneous coordinates.

This multiplies the homogeneous coordinates with the values w. w normally is a constant or an array with shape self.shape[:-1]. It then multiplies all 4 coordinates of a point with the same value, thus resulting in a denormalization while keeping the position of the point unchanged.

The denormalization of the coordinates is done in place. If the Coords4 object was normalized, it will have precisely w as its 4-th coordinate value after the call.

toCoords()

Convert homogeneous coordinates to cartesian coordinates.

Returns a Coords object with the cartesian coordinates of the points. Points at infinity (w=0) will result in Inf or NaN value. If there are no points at infinity, the resulting Coords point set is equivalent to the Coords4 one.

npoints()

Return the total number of points.

x()

Return the x-plane

y()

Return the y-plane

z()

Return the z-plane

w()

Return the w-plane

bbox()

Return the bounding box of a set of points.

Returns the bounding box of the cartesian coordinates of the object.

actor(**kargs)

Graphical representation

Functions defined in module nurbs

nurbs.toCoords4(x)

Convert cartesian coordinates to homogeneous

x: :class:Coords
Array with cartesian coordinates.

Returns a Coords4 object corresponding to the input cartesian coordinates.

Documentation

Previous topic

32. geomtools — Basic geometrical operations.

Next topic

34. isopar — Isoparametric transformations

This Page