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

SclLineIntersect

Overview

Find the point of intersection, the X and Y coordinates, of two lines.

Synopsis

SclLineIntersect $x1 $y1 $x2 $y2 $x3 $y3 $x4 $y4 xint yint

Description

The intersection point of the lines defined by x1,y1 to x2,y2 and x3,y3 to x4,y4 is found and the type of intersection is reported as the return value of the command.

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
  • Pass by value. Coordinates of the start point of the first line.

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

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

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

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

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 x2 100.0
set y2 100.0
set x3 0.0
set y3 100.0
set x4 100.0
set y4 0.0
set intResult [SclLineIntersect $x1 $y1 $x2 $y2 $x3 $y3 $x4 $y4 xint yint]
puts $intResult
if {$intResult == -1} {
  puts "Lines are parallel"
} elseif {$intResult == 0} {
  puts "Lines externally intersect at x=$xint, y=$yint"
} elseif {$intResult == 1} {
  puts "Lines internally intersect at x=$xint, y=$yint"
} else {
  puts "FATAL ERROR CONDITION - THIS SHOULD NEVER HAPPEN"
}