p3d.geo module

From p3d
Jump to: navigation, search

The p3d.geo module holds the TransformationMatrix and Plane class with a set of linear algebra functions. Both Classes work with the p3d.atom.Atom class or p3d.vector.Vector class.

TransformationMatrix class

p3d.geo.TransformationMatrix(source,dest)

The initialisation of a TransformationMatrix object requires a set of three source vectors and a set of three destination vectors.

e.g.

>>> a = p3d.vector.Vector( 1, 0, 0)
>>> b = p3d.vector.Vector( 0, 1, 0)
>>> c = p3d.vector.Vector( 0, 0, 1)
>>> source = [a,b,c]

>>> d = p3d.vector.Vector(-1, 0, 0)
>>> e = p3d.vector.Vector( 0,-1, 0)
>>> f = p3d.vector.Vector( 0, 0, 1)
>>> dest = [d,e,f]
>>> TM = p3d.geo.TransformationMatrix(source,dest)

>>> t = p3d.vector.Vector(2,3,4)
>>> (TM*t).info()
'[  -2.000,  -3.000,   4.000]'

Plane class

p3d.geo.Plane(a,b,c)

The initialisation of a Plane object requires three vectors/atoms.

Attributes

n ⇒ plane normal vector

d ⇒ Distance to origine

D ⇒ Plane Basis Vector = Plane Normal times distance

Methods

The examples shown use

a = p3d.vector.Vector( 1, 1,1)
b = p3d.vector.Vector( -1, 1,1)
c = p3d.vector.Vector(-1,-1,1)
P = p3d.geo.Plane(a,b,c)

P is a plane parallel to the xy plane intersecting at z = 1 .. any Atom will work equally to define a Plane.

projectionOfVector
returns new Vector = projected vector given as argument onto plane
>>> t = p3d.vector.Vector(7,0,0)
>>> P.projectionOfVector(t).info()
'[   7.000,   0.000,   1.000]'