# pwu::Vector3

Utility functions for three dimensional vectors, which are represented as a list of three real values.

Summary
 pwu:: Vector3 Utility functions for three dimensional vectors, which are represented as a list of three real values. Static Actions zero Return the 3 dimensional zero vector set Return a vector with the given x, y and z components index Return the value of the vector at the given index x Return the x component of the vector y Return the y component of the vector z Return the z component of the vector equal Check if two vectors are equal notEqual Check if two vectors are not equal add Add two vectors together and return the result subtract Subtract one vector from another and return the result negate Return the negation of a vector scale Scale a vector by a single scalar value divide Scale a vector by inverse of a single scalar value multiply Return a vector that is the components of two vectors multiplied together cross Return the cross product of two vectors dot Calculate the dot product of two vectors normalize Return the normalization of a vector length Return the length of the vector distanceToLine Return the distance of the vector to a line minimum Return a vector that has the minimum components of two vectors maximum Return a vector that has the maximum components of two vectors affine Return a vector that is the affine combination of two vectors barycentric Return a vector that has the barycentric coordinates of the given point in the frame of the given three vectors intersect Return a vector that is the intersection of the two lines specified as two point and direction pairs.

### zero

 pwu::Vector3 zero

Return the 3 dimensional zero vector

none

#### Returns

a vector with the given x and y

### set

 pwu::Vector3 set x y z

Return a vector with the given x, y and z components

#### Parameters

 x the x component y the y component z the z component

#### Returns

a vector with the given x and y

### index

 pwu::Vector3 index vec i

Return the value of the vector at the given index

#### Parameters

 vec the vector i the index to get; [0, 2]

#### Returns

the value of the vector at the given index

### x

 pwu::Vector3 x vec

Return the x component of the vector

#### Parameters

 vec the vector

#### Returns

the x component of the vector

### y

 pwu::Vector3 y vec

Return the y component of the vector

#### Parameters

 vec the vector

#### Returns

the y component of the vector

### z

 pwu::Vector3 z vec

Return the z component of the vector

#### Parameters

 vec the vector

#### Returns

the z component of the vector

### equal

 pwu::Vector3 equal ?-tolerance tol? vec1 vec2

Check if two vectors are equal

#### Parameters

 tol the tolerance to check equality, 0.0 is used if not given vec1 the first vector vec2 the second vector

#### Returns

true if the vectors are equal within tolerance

### notEqual

 pwu::Vector3 notEqual ?-tolerance tol? vec1 vec2

Check if two vectors are not equal

#### Parameters

 tol the tolerance to check equality, 0.0 is used if not given vec1 the first vector vec2 the second vector

#### Returns

true if the vectors are not equal within tolerance

Add two vectors together and return the result

#### Parameters

 vec1 the first vector vec2 the second vector

#### Returns

the sum of the two vectors

### subtract

 pwu::Vector3 subtract vec1 vec2

Subtract one vector from another and return the result

#### Parameters

 vec1 the first vector vec2 the second vector

#### Returns

the difference of the two vectors

### negate

 pwu::Vector3 negate vec

Return the negation of a vector

#### Parameters

 vec the vector

#### Returns

the negated vector

### scale

 pwu::Vector3 scale vec scalar

Scale a vector by a single scalar value

#### Parameters

 vec the vector scalar a scalar value

#### Returns

a vector scaled by the scalar

### divide

 pwu::Vector3 divide vec scalar

Scale a vector by inverse of a single scalar value

#### Parameters

 vec the vector scalar a scalar value

#### Returns

a vector divided by the scalar

### multiply

 pwu::Vector3 multiply vec1 vec2

Return a vector that is the components of two vectors multiplied together

#### Parameters

 vec1 the first vector vec2 the second vector

#### Returns

the component multiply of the two vectors

### cross

 pwu::Vector3 cross vec1 vec2

Return the cross product of two vectors

#### Parameters

 vec1 the first vector vec2 the second vector

#### Returns

the cross product of the two vectors

### dot

 pwu::Vector3 dot vec1 vec2

Calculate the dot product of two vectors

#### Parameters

 vec1 the first vector vec2 the second vector

#### Returns

the dot product of the two vectors

### normalize

 pwu::Vector3 normalize ?-length lenVar? vec

Return the normalization of a vector

#### Parameters

 vec the vector lenVar a variable name to set the length of the vector before being normalized

#### Returns

the normalized vector

### length

 pwu::Vector3 length vec

Return the length of the vector

#### Parameters

 vec the vector

#### Returns

the length of the vector

### distanceToLine

 pwu::Vector3 distanceToLine vec pt dir

Return the distance of the vector to a line

#### Parameters

 vec the vector pt the origin point of the line dir the direction vector of the line

#### Returns

the perpendicular distance of the vector to the line

### minimum

 pwu::Vector3 minimum vec1 vec2

Return a vector that has the minimum components of two vectors

#### Parameters

 vec1 the first vector vec2 the second vector

#### Returns

the minimum vector

### maximum

 pwu::Vector3 maximum vec1 vec2

Return a vector that has the maximum components of two vectors

#### Parameters

 vec1 the first vector vec2 the second vector

#### Returns

the maximum vector

### affine

 pwu::Vector3 affine s vec1 vec2

Return a vector that is the affine combination of two vectors

#### Parameters

 s the affine scalar vec1 the first vector vec2 the second vector

#### Returns

A linearly interpolated point along the directed line from vec1 to vec2.  An s of 0.0 returns vec1 and and s of 1.0 returns vec2.  Values of s less than 0.0 and greater than 1.0 are valid.  When s is less than 0.0, the point returned would be before vec1.  When s is greater than 1.0, the point returned would be after vec2.

#### Example

Code

`# Capture extents of all database entitieslassign [pw::Database getExtents] minExt maxExt# Compute extents centroidset centroidPt [pwu::Vector3 affine 0.5 \$minExt \$maxExt]# Enlarge extents diagonal by 10%set minExt10 [pwu::Vector3 affine -0.1 \$minExt \$maxExt]set maxExt10 [pwu::Vector3 affine 1.1 \$minExt \$maxExt]puts "minExt     : [list \$minExt]"puts "maxExt     : [list \$maxExt]"puts "centroidPt : [list \$centroidPt]"puts "minExt10   : [list \$minExt10]"puts "maxExt10   : [list \$maxExt10]"`

Output

`minExt     : {10.000170704427509 -14.405848937908303 -9.049999999999983}maxExt     : {40.0 65.59615106209186 50.95000000000002}centroidPt : {25.000085352213755 25.59515106209178 20.950000000000017}minExt10   : {7.000187774870261 -22.40604893790832 -15.049999999999985}maxExt10   : {42.99998292955725 73.59635106209188 56.950000000000024}`

### barycentric

 pwu::Vector3 barycentric pt vec1 vec2 vec3

Return a vector that has the barycentric coordinates of the given point in the frame of the given three vectors

#### Parameters

 pt the point to find the barycentric coordinates of vec1 the first vector vec2 the second vector vec3 the third vector

#### Returns

The barycentric coordinates vector.

### intersect

 pwu::Vector3 intersect ?-tolerance tol? anchor1 dir1 anchor2 dir2

Return a vector that is the intersection of the two lines specified as two point and direction pairs.

#### Parameters

 tolerance This parameter specifies the maximum distance allowed between the closest points of approach on each line.  If the tolerance is exceeded, an error is raised.  A value of 0.0 (the default) or less disables this check. anchor1 This parameter is the start point of the first line. dir1 This value is the direction of the first line from anchor1. anchor2 This parameter is the start point of the second line. dir2 This value is the direction of the second line from anchor2.

#### Returns

The return value is a vector representing the intersection of the two lines.  If the lines do not intersect, the behavior differs based on whether a tolerance is specified.  If no tolerance is given, the return value represents the midpoint of the points on each line closest to the other line.  If the two lines are parallel, the return value will be the midpoint of the two anchor points.  If a tolerance is given and the two lines do not intersect or cross within the given tolerance, an error is raised.  Otherwise, the return value is the same as if no tolerance was specified.

#### Example

Code

`# Intersect two lines at 90 degreesset iPt [pwu::Vector3 intersect {0 0 0} {1 0 0} {1 -1 0} {0 1 0}]puts \$iPt# Intersect two lines at 90 degrees in different planesset iPt [pwu::Vector3 intersect {0 0 0} {1 0 0} {1 -1 1} {0 1 0}]puts \$iPt# Fail to intersect two lines within a given tolerancecatch {pwu::Vector3 intersect -tolerance 0.1 {0 0 0} {1 0 0} \   {1 -1 1} {0 1 0}} msgputs \$msg# Try to intersect two parallel lines with no toleranceset iPt [pwu::Vector3 intersect {0 0 0} {1 0 0} {0 -1 0} {1 0 0}]puts \$iPt# Try to intersect two parallel lines with a tolerancecatch {pwu::Vector3 intersect -tolerance 0.1 {0 0 0} {1 0 0} \   {0 -1 0} {1 0 0}} msgputs \$msg`

Output

`1.0 0.0 0.01.0 0.0 0.5ERROR: Lines do not intersect within the given tolerance.0.0 -0.5 0.0ERROR: Lines are parallel.`
 pwu::Vector3 zero
Return the 3 dimensional zero vector
 pwu::Vector3 set x y z
Return a vector with the given x, y and z components
 pwu::Vector3 index vec i
Return the value of the vector at the given index
 pwu::Vector3 x vec
Return the x component of the vector
 pwu::Vector3 y vec
Return the y component of the vector
 pwu::Vector3 z vec
Return the z component of the vector
 pwu::Vector3 equal ?-tolerance tol? vec1 vec2
Check if two vectors are equal
 pwu::Vector3 notEqual ?-tolerance tol? vec1 vec2
Check if two vectors are not equal
Add two vectors together and return the result
 pwu::Vector3 subtract vec1 vec2
Subtract one vector from another and return the result
 pwu::Vector3 negate vec
Return the negation of a vector
 pwu::Vector3 scale vec scalar
Scale a vector by a single scalar value
 pwu::Vector3 divide vec scalar
Scale a vector by inverse of a single scalar value
 pwu::Vector3 multiply vec1 vec2
Return a vector that is the components of two vectors multiplied together
 pwu::Vector3 cross vec1 vec2
Return the cross product of two vectors
 pwu::Vector3 dot vec1 vec2
Calculate the dot product of two vectors
 pwu::Vector3 normalize ?-length lenVar? vec
Return the normalization of a vector
 pwu::Vector3 length vec
Return the length of the vector
 pwu::Vector3 distanceToLine vec pt dir
Return the distance of the vector to a line
 pwu::Vector3 minimum vec1 vec2
Return a vector that has the minimum components of two vectors
 pwu::Vector3 maximum vec1 vec2
Return a vector that has the maximum components of two vectors
 pwu::Vector3 affine s vec1 vec2
Return a vector that is the affine combination of two vectors
 pwu::Vector3 barycentric pt vec1 vec2 vec3
Return a vector that has the barycentric coordinates of the given point in the frame of the given three vectors
 pwu::Vector3 intersect ?-tolerance tol? anchor1 dir1 anchor2 dir2
Return a vector that is the intersection of the two lines specified as two point and direction pairs.