A generic size VectorN class derived from Array, basically a 1 dimensional Array.
Most methods and behavior are herited from Array, with the limitation that a MatrixN must have exactly 2 dimensions.
>>> V = VectorN()
>>> V
VectorN([])
>>> V = VectorN([0, 1, 2])
>>> V
VectorN([0, 1, 2])
>>> V = VectorN(0, 1, 2)
>>> V
VectorN([0, 1, 2])
>>> M = MatrixN([[0], [1], [2]])
>>> print M.formated()
[[0],
[1],
[2]]
>>> V = VectorN(M.col[0])
>>> V
VectorN([0, 1, 2])
The VectorN class has a constant ndim of 1
>>> VectorN.ndim
1
>>> V.ndim
1
>>> VectorN.ndim = 2
Traceback (most recent call last):
...
AttributeError: attribute ndim is a read only class attribute and cannot be modified on class VectorN
>>> V.ndim = 2
Traceback (most recent call last):
...
AttributeError: 'VectorN' object attribute 'ndim' is read-only
It’s protected against initialization or resizing to a shape that wouldn’t be a VectorN anymore
>>> V = VectorN([[0, 1], [2, 3]])
Traceback (most recent call last):
...
TypeError: cannot initialize a VectorN of shape (4,) from [[0, 1], [2, 3]] of shape (2, 2),
as it would truncate data or reduce the number of dimensions
>>> V.resize((2, 2))
Traceback (most recent call last):
...
TypeError: new shape (2, 2) is not compatible with class VectorN
Other Array types can be cast to VectorN, but truncating data or reducing dimensions is not allowed to avoid silent loss of data in a conversion, use an explicit resize / trim / sub-array extraction
>>> A = Array(range(4), shape=(4,))
>>> V = VectorN(A)
>>> V
VectorN([0, 1, 2, 3])
>>> A = Array(range(4), shape=(2, 2))
>>> V = VectorN(A)
Traceback (most recent call last):
...
TypeError: cannot cast a Array of shape (2, 2) to a VectorN of shape (4,),
as it would truncate data or reduce the number of dimensions
As for Array, __init__ is a shallow copy, note that as VectorN don’t have sub-arrays, shallow and deep copy amounts to the same thing.
>>> A = Array(range(4), shape=(4,))
>>> V = VectorN(A)
>>> V == A
False
>>> V is A
False
>>> V.isEquivalent(A)
True
>>> V[0] == A[0]
True
>>> V[0] is A[0]
True
u.angle(v) <==> angle(u, v) –> float
Returns the angle of rotation between u and v, 3 dimensional Vectors representing 3D vectors.
Note : this angle is not signed, use axis to know the direction of the rotation
Alternatively can use the form a.angle(b, c), where a, b, c are 4 dimensional Vectors representing 3D points, it is then equivalent to angle(b-a, c-a)
Returns the axis of rotation from u to v as the vector n = u ^ v, u and v being 3 dimensional Vectors representing 3D vectors. If the normalize keyword argument is set to True, n is also normalized.
Alternatively can use the form a.axis(b, c), where a, b, c are 4 dimensional Vectors representing 3D points, it is then equivalent to axis(b-a, c-a).
Returns the cotangent of the u, v angle, u and v should be 3 dimensional Vectors representing 3D vectors.
Alternatively can use the form a.cotan(b, c), where a, b, c are 4 dimensional Vectors representing 3D points, it is then equivalent to cotan(b-a, c-a)
cross product of u and v, u and v should be 3 dimensional vectors.
dot product of u and v, u and v should be Vectors of identical size.
u.isParallel(v[, tol]) –> bool
Returns True if both arguments considered as VectorN are parallel within the specified tolerance
u.length() –> float
Returns the length of u, ie sqrt(u.dot(u))
u.normal() –> VectorN
Returns a normalized copy of self. Overriden to be consistant with Maya API and MEL unit command, does not raise an exception if self if of zero length, instead returns a copy of self
Outer product of vectors u and v
Returns the projection of this vector onto other vector.
v.shape : tuple of one int
Shape of the VectorN, as Vectors are one-dimensional Arrays: v.shape = (v.size,).
It can be queried, or set to change the VectorN’s shape similarly to the resize method, as the only way to change a VectorN’s shape is to resize it.
>>> V = VectorN(1, 2, 3)
>>> V
VectorN([1, 2, 3])
>>> V.shape=(4)
>>> V
VectorN([1, 2, 3, 0])
>>> V.shape=(2, 2)
Traceback (most recent call last):
...
TypeError: new shape (2, 2) is not compatible with class VectorN
Related : see Array.resize method.
Number of components in the VectorN
u.sqlength() –> float
Returns the square length of u, ie u.dot(u).
u.transformAsNormal(m) –> VectorN
Equivalent to transforming u by the inverse transpose MatrixN of m, used to transform normals.
u.normal() –> VectorN
Returns a normalized copy of self. Overriden to be consistant with Maya API and MEL unit command, does not raise an exception if self if of zero length, instead returns a copy of self