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

Summary

pwu:: | 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. |

pwu::Vector3 affine s vec1 vec2

Return a vector that is the affine combination of two vectors

s | the affine scalar |

vec1 | the first vector |

vec2 | the second vector |

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.

Code

# Capture extents of all database entities lassign [pw::Database getExtents] minExt maxExt # Compute extents centroid set 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}

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

pt | the point to find the barycentric coordinates of |

vec1 | the first vector |

vec2 | the second vector |

vec3 | the third vector |

The barycentric coordinates vector.

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.

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. |

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.

Code

# Intersect two lines at 90 degrees set 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 planes set 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 tolerance catch {pwu::Vector3 intersect -tolerance 0.1 {0 0 0} {1 0 0} \ {1 -1 1} {0 1 0}} msg puts $msg # Try to intersect two parallel lines with no tolerance set 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 tolerance catch {pwu::Vector3 intersect -tolerance 0.1 {0 0 0} {1 0 0} \ {0 -1 0} {1 0 0}} msg puts $msg

Output

1.0 0.0 0.0 1.0 0.0 0.5 ERROR: Lines do not intersect within the given tolerance. 0.0 -0.5 0.0 ERROR: Lines are parallel.

Return the 3 dimensional zero vector

pwu::Vector3 zero

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

pwu::Vector3 set x y z

Return the value of the vector at the given index

pwu::Vector3 index vec i

Return the x component of the vector

pwu::Vector3 x vec

Return the y component of the vector

pwu::Vector3 y vec

Return the z component of the vector

pwu::Vector3 z vec

Check if two vectors are equal

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

Check if two vectors are not equal

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

Add two vectors together and return the result

pwu::Vector3 add vec1 vec2

Subtract one vector from another and return the result

pwu::Vector3 subtract vec1 vec2

Return the negation of a vector

pwu::Vector3 negate vec

Scale a vector by a single scalar value

pwu::Vector3 scale vec scalar

Scale a vector by inverse of a single scalar value

pwu::Vector3 divide vec scalar

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

pwu::Vector3 multiply vec1 vec2

Return the cross product of two vectors

pwu::Vector3 cross vec1 vec2

Calculate the dot product of two vectors

pwu::Vector3 dot vec1 vec2

Return the normalization of a vector

pwu::Vector3 normalize ?-length lenVar? vec

Return the length of the vector

pwu::Vector3 length vec

Return the distance of the vector to a line

pwu::Vector3 distanceToLine vec pt dir

Return a vector that has the minimum components of two vectors

pwu::Vector3 minimum vec1 vec2

Return a vector that has the maximum components of two vectors

pwu::Vector3 maximum vec1 vec2

Return a vector that is the affine combination of two vectors

pwu::Vector3 affine s vec1 vec2

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

pwu::Vector3 barycentric pt vec1 vec2 vec3

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

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