You are here: Surpac Concepts > Macros > SCL > Geometry and Maths > Scl3DLineIntersect
GEOVIA Surpac

Scl3DLineIntersect

Overview

You can use scl3DLineIntersect to find the point of intersection between two lines in 3D space, if the distance between the two lines at the point of intersection is less than a specified tolerance.

Synopsis

Scl3DLineIntersect $x1 $y1 $z1 $x2 $y2 $z2 $x3 $y3 $z3 $x4 $y4 $z4 $tolerance xint yint zint dist_int

Description

The intersection point of the lines defined by x1,y1,z1 to x2,y2,z2 and x3,y3,z3 to x4,y4,z4 is found provided the distance between the two lines at the point of intersection is less than the defined tolerance. The coordinates of the point of intersection are assigned to the variables xint, yint and zint. The seperation of the lines at the point of intersection is assigned to the dist_int variable.

The intersection type is identified as internal or external to the two line segments. The case of parallel lines is also detected. In the case of parallel lines the intersection coordinates are not assigned a value so the intersection code must be tested to determine what action to take.

Arguments

  • x1, y1, z1
  • Pass by value. Coordinates of the start point of the first line.

  • x2, y2, z2
  • Pass by value. Coordinates of the end point of the first line.

  • x3, y3, z3
  • Pass by value. Coordinates of the start point of the second line.

  • x4, y4, z4
  • Pass by value. Coordinates of the end point of the second line.

  • tolerance
  • Pass by value. If the seperation of the two lines at the point of intersection is less than this tolerance then an intersection is considered to exist. If exact intersecions are required then use 0.0 for the tolerance. Progressively greater values for tolerance will detect intersections that are progressively more approximate.

  • xint, yint, zint
  • Pass by reference. Coordinates of the intersection point subject to the intersection code defining that the lines intersect are stored in these variables.

  • dist_int
  • Pass by reference. The distance between the two lines at the point of intersection, assuming the lines are not parallel, is stored in this variable.

Returns

An integer value indicating the intersection type.

  • -1 - The lines are parallel
  • 0 - The lines externally intersect. That is, at least one of the lines has been extended to obtain an intersection.
  • 1 - The lines internally intersect. That is the intersection point exists between the end points of both line segments.

Examples

set x1 0.0
set y1 0.0
set z1 0.0
set x2 100.0
set y2 100.0
set z2 100.0
set x3 0.0
set y3 100.0
set z3 0.0
set x4 100.0
set y4 0.0
set z4 100.0
set intResult [Scl3DLineIntersect $x1 $y1 $z1 $x2 $y2 $z2 $x3 $y3 $z3 
$x4 $y4 $z4 0.0 xint yint zint dist_int]
puts $intResult
if {$intResult == -1} {
 puts "Lines are parallel"
} elseif {$intResult == 0} {
 puts "Lines externally intersect at x=$xint, y=$yint, z=$zint"
 puts "Line seperation at intersection point = $dist_int"
} elseif {$intResult == 1} {
 puts "Lines internally intersect at x=$xint, y=$yint, z=$zint"
 puts "Line seperation at intersection point = $dist_int"
} else {
 puts "FATAL ERROR CONDITION - THIS SHOULD NEVER HAPPEN"
}