Position Class

From TouchDesigner 099 Wiki

The position class holds a single 3 component position. A position is a single point in space, and it's important to use a position or vector as appropriate for the data that is being calculated, since matrix operations on them will end in different results. When being multiplied by a Matrix, this class will implicitly have a 4th component (W component) of 1. If the Matrix is a projection matrix that will cause the W component to become something other than 1, all 4 components will be divided by W to make the position homogeneous again. A new position can be created without any arguments, with 3 arguments for the x,y,z values, or with a single argument which is a variable that has 3 entries such as a list of length 3, or another position or vector. Examples of creating a position:

 p = tdu.Position() # starts as (0, 0, 0)
 p2 = tdu.Position(1, 5, 0)
 values = [0, 1, 0]
 p3 = tdu.Position(values)


Members

x Gets or sets the X component of the position.
y Gets or sets the Y component of the position.
z Gets or sets the Z component of the position.


Methods

scale(x, y, z)

Scales each component of the position by the specified values.
  • x, y, z - The values to scale each component of the position by.
 p.scale(1, 2, 1)

translate(x, y, z)

Translates the position by the specified values.
  • x, y, z - The values to translate by.
 p.translate(5, 2, 0)


copy()Position

Returns a new position that is a copy of the position.
 newV = v.copy()

Special Functions

[i]float

Gets or sets the component of the position specified by i, where i can be 0, 1, or 2.
   y = p[1]
   p[1] = y + 2.0

Position * floatPosition
float * PositionPosition

Scales the position by the give float scalar and returns a new Position as the result.

Position + floatPosition
float + PositionPosition

Adds the given scalar to all 3 components of the position and returns a new position as the result.

Position - floatPosition
float - PositionPosition

Subtracts the given scalar from all 3 components of the position and returns a new position as the result.

Vector + PositionPosition
Position + VectorPosition

Adds the vector to the position. ie. it displaces the given position by the vector. Returns a new position as the result.

Position - VectorPosition

Subtracts the vector from the position. Notice that the reverse is not a legal operation: subtracting a position from a vector does not have any meaning. Returns a new position with the results.


Position - PositionVector

Subtracts the two positions to create a vector that is pointing from the 2nd one to the 1st one, with length equal to the distance between the positions.

Position += float

Adds the given scalar to all 3 components of the position, the position will contain the result of the operation.

Position += Vector

Displaces the position by the given vector, the position will contain the result of the operation.

Position -= float

Subtracts the given scalar from all 3 components of the position, the position will contain the result of the operation.

Position -= Vector

Displaces the position by the given vector, the position will contain the result of the operation.

Matrix * PositionPosition

Multiplies the Position by the matrix and returns the a new position as the result.

Position / floatPosition

Divides each component of the position by the scalar and returns the a new position as the result.

Position *= Matrix

Multiplies the position by the matrix, the position will contain the result. The is position multiplied on the right of the matrix. It is the equivalent of doing Position = Matrix * Position.

Position *= float

Scales all 3 components of the position by the given scalar. The position will contain the result.

Position *= Position

Component-wise multiplies the 3 components of the first position by the 3 components of the 2nd position.

abs(Position)Position

Returns a new position with all 3 components being the absolute value of the given position's components.

-PositionPosition

Returns a new position with all 3 component's being negated.

Miscellaneous

__getstate__()dict

Returns a dictionary with persistent data about the object suitable for pickling and deep copies.

__setstate__(dict)

Reads the dictionary to update persistent details about the object, suitable for unpickling and deep copies.