24. geometry
— A generic interface to the Coords transformation methods¶
This module defines a generic Geometry superclass which adds all the possibilities of coordinate transformations offered by the Coords class to the derived classes.
-
class
geometry.
Geometry
[source]¶ A virtual base class for all geometry classes in pyFormex.
The Geometry class is a generic parent class for all geometry classes in pyFormex. It is not intended to be used directly, but only through derived classes. Examples of derived classes are
Formex
,Mesh
,TriSurface
,PolyLine
,BezierSpline
,Polygons
.The basic entity of geometry is the point, defined by its coordinates. The Geometry class expects these to be stored in a
Coords
object assigned to thecoords
attribute (it is the responsability of the derived class object initialisation to do this).The Geometry class exposes the following attributes of the
coords
attribute, so that they can be directly used on the Geometry object:xyz
,x
,y
,z
,xy
,yz
,xz
.The Geometry class exposes a large set of Coords methods for direct use on the derived class objects. These methods are automatically executed on the
coords
attribute of the object. One set of such methods are those returning some information about the Coords:points()
,bbox()
,center
,bboxPoint()
,centroid()
,sizes()
,dsize()
,bsphere()
,bboxes()
,inertia()
,principalCS()
,principalSizes()
,distanceFromPlane()
,distanceFromLine()
,distanceFromPoint()
,directionalSize()
,directionalWidth()
,directionalExtremes()
. Thus, if F is an instance of classFormex
, then one can useF.center()
as a convenient shorthand forF.coords.center()
.Likewise, most of the transformation methods of the :class:~coords.Coords` class are exported through the Geometry class to the derived classes. When called, they will return a new object identical to the original, except for the coordinates, which are transformed by the specified method. Refer to the correponding
Coords
method for the precise arguments of these methods:scale()
,adjust()
,translate()
,centered()
,align()
,rotate()
,shear()
,reflect()
,affine()
,toCS()
,fromCS()
,transformCS()
,position()
,cylindrical()
,hyperCylindrical()
,toCylindrical()
,spherical()
,superSpherical()
,toSpherical()
,circulize()
,bump()
,flare()
,map()
,map1()
,mapd()
,copyAxes()
,swapAxes()
,permuteAxes()
,rollAxes()
,projectOnPlane()
,projectOnSphere()
,projectOnCylinder()
,isopar()
,addNoise()
,rot()
,trl()
.Geometry is a lot more than points however. Therefore the Geometry and its derived classes can represent higher level entities, such as lines, planes, circles, triangles, cubes,… These entities are often represented by multiple points: a line segment would e.g. need two points, a triangle three. Geometry subclasses can implement collections of many such entities, just like the
Coords
can hold many points. We call these geometric entities ‘elements’. The subclass must at least define a methodnelems()
returning the number of elements in the object, even if there is only one.The Geometry class allows the attribution of a property number per element. This is an integer number that can be used as the subclass or user wants. It could be just the element number, or a key into a database with lots of more element attributes. The Geometry class provides methods to handle these property numbers.
The Geometry class provides a separate mechanism to store attributes related to how the geometry should be rendered. For this purpose the class defines an
attrib
attribute which is an object of classAttributes
. This attribute is callable to set any key/value pairs in its dict. For example,F.attrib(color=yellow)
will make the object F always be drawn in yellow.The Geometry class provides for adding fields to instances of the derived classes. Fields are numerical data (scalar or vectorial) that are defined over the geometry. For example, if the geometry represents a surface, the gaussian curvature of that surface is a field defined over the surface. Field data are stored in
Field
objects and the Geometry object stores them internally in a dict object with the field name as key. The dict is kept in an attributefields
that is only created when the first Field is added to the object.Finally, the Geometry class also provides the interface for storing the Geometry object on a file in pyFormex’s own ‘pgf’ format.
Note
When subclassing the Geometry class, care should be taken to obey some rules in order for all the above to work properly. See UserGuide.