math3d: Support for coordinate-free geometry using numpy

See A Coordinate Free Geometry ADT and Nathan Litke’s Coordinate Free Geometric Programming for inspiration.

Points are “column” vectors.

TODO: Need to support general VRML transformations as well as simple translation and pure rotation transformations.

class Point

Bases: numpy.ndarray

Floating point triplet representing a point

close(a, **kw)

Return if Point is close to another Point using numpy.allclose

class Vector

Bases: numpy.ndarray

Floating point triplet representing a vector

close(a, **kw)

Return if Vector is close to another Vector using numpy.allclose

length()

compute length of vector

normalize()

convert to unit length vector

sqlength()

compute square length of vector

class Xform(matrix, orthonormalize=True, _valid=False, _isIdentity=False, _pure=False, _projection=False)

Bases: builtins.object

4x4 matrix for homogeneous point and vector transformation

When transformations are multiplied left-to-right, the right-most transformations transform the Point/Vector first, i.e., are more local.

Member functions that make in-place modifications, left multiply the current matrix, i.e., make a global change.

make_orthonormal()

orthonormalize rotation part of transformation

rotate(axis, angle)

Further rotate

scale(vector)

Further scale

translate(offset)

Further translate

weighted_point(points, weights=None)

return weighted sum of Points

If no weights are given, then return average.

cross(v1, v2)

Same as numpy.cross but return a Vector if arguments are Vectors

Identity()

Identify transformation

Rotation(axis, angle, inDegrees=False)

Build a rotation transformation

Translation(offset)

Build a translation transformation

Scale(vector)

Build a scaling transformation

transform(translation=None, center=None, rotation=None, scaleOrientation=None, scale=None)

X3D transformation specification into single transformation

All angles must be in radians.

look_at(p0, p1, up)

Compute viewing transformation

Place :param p0: at origin, :param p1: on the negative z axis, and orient so :param up: is in the same half-plane as the postive y axis and z axis. :param up: can either be a Point or a Vector.

ortho(left, right, bottom, top, hither, yon)

return 4x4 orthographic transformation

frustum(left, right, bottom, top, hither, yon)

return 4x4 perspective transformation

perspective(fov_y, aspect, z_near, z_far)

return 4x4 perspective transformation

camera_orientation(p0, p1, up)

Like look_at but p1 is at origin

Place :param p0: on positive z axis origin, :param p1: at the origin, and orient so :param up: is in the same half-plane as the postive y axis and z axis. :param up: can either be a Point or a Vector.

class BBox(llb=None, urf=None)

Bases: builtins.object

right-handed axis-aligned bounding box

If either BBox.llb or BBox.urf are None, then the bounding box is uninitialized.

add(pt)

expand bounding box to encompass given point

Parameters:pt – a Point or other XYZ-tuple
add_bbox(box)

expand bounding box to encompass given bounding box

Parameters:box – a BBox
bulk_add(pts)

expand bounding box to encompass all given points

Parameters:pts – a numpy array of XYZ coordinates
center()

return center of bounding box

Return type:a Point
llb

lower-left-back corner coordinates, a Point

size()

return length of sides of bounding box

Return type:a Vector
urf

upper-right-front corner coordinates, a Point

xform(xf)

transform bounding box in place

This Page