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