For example, in py2rhino there is a package called util. This contains a module named 'vector' and 'point', both of which contain a useful set of functions to work with vectors and points. For example you can get the cross product of two vectors like this
import py2rhino as p2r
v1 = (3,8,1)
v2 = (4,4,9)
v3 = p2r.util.vector.cross_product(v1, v2)
In order to avoid having to do so much typing, I tend to import these modules separately, like this:
import py2rhino.util.vector as v
v1 = (3,8,1)
v2 = (4,4,9)
v3 = v.cross_product(v1, v2)
Some other useful functions in the vector module are unitize (which forces the vector to be 1 unit long), and scale (which scales the vector by a certain amount).
No comments:
Post a Comment