Position Class

From Derivative
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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

xfloat :

Gets or sets the X component of the position.

yfloat :

Gets or sets the Y component of the position.

zfloat :

Gets or sets the Z component of the position.

Methods

translate(x, y, z)None:

Translates the position by the specified values.

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

scale(x, y, z)None:

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)

copy()tdu.Position:

Returns a new position that is a copy of the position.

newV = v.copy()

Special Functions[edit]

tdu.Position[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

tdu.Position * floattdu.Position:

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

p = p * 0.1
p = 0.1 * p

tdu.Position + floattdu.Position:

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

p = p + 1.2
p = 1.2 + p

tdu.Position - floattdu.Position:

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

p = p - 1.2
p = 1.2 - p

tdu.Vector + tdu.Positiontdu.Position:

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

p2 = v + p1
p2 = p1 + v

tdu.Position - tdu.Vectortdu.Position:

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.

p2 = p1 - v

tdu.Position - tdu.Positiontdu.Vector:

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.

v = p1 - p2

tdu.Position += floatNone:

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

p += 0.1

tdu.Position += tdu.VectorNone:

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

p += v

tdu.Position -= floatNone:

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

p -= 0.4

tdu.Position -= tdu.VectorNone:

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

p -= v

tdu.Matrix * tdu.Positiontdu.Position:

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

p2 = m * p1

tdu.Position / floattdu.Position:

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

p2 = p1 / 2.0

tdu.Position *= tdu.MatrixNone:

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.

p *= m

tdu.Position *= floatNone:

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

p *= 1.3

tdu.Position *= tdu.PositionNone:

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

p1 *= p2

abs(tdu.Position)tdu.Position:

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

p2 = abs(p1)

-tdu.Positiontdu.Position:

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

p2 = -p1

TouchDesigner Build: