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

SclIntersectSegments

Overview

You can use SclIntersectSegments to intersect, outersect or union two segments to create a new segment or segments. Depending on the geometric relationship of the two segments with respect to each other the result may be no segments at all, a single segment or multiple segments.

Synopsis

SclIntersectSegments $Segment1Handle $Operation $Segment2Handle $ResultSwaHandle $ResultStringId

Description

Perform the specified geomegtric operation, intersect, outersect or union of Segment1Handle against Segment2Handle. Store the resulting segments, if any are created, in the SWA referenced by ResultSwaHandle with the string number of the result defined by ResultStringId.

The descriptions of the resultant segment will come from the points of Segment2Handle.

Both segments must be closed for this command to work successfully.

Arguments

  • Segment1Handle
  • Pass by Value. The handle to the segment that is sometimes referred to as the interecting, outersecting or unioning segment. THe segment must be closed.

  • Operation
  • Pass by value. The operation that will be used when the intersecting (or outersecting or unioning) segment is applied to the intersected (or outersected or unioned) segment. Permited values for the operation are:

    • intersect
    • The resultant segment/s, if any, define the area common to both the intersecting and intersected segments. The geometry of the result is identical regardless of the order in which the segments are used with the intersect operation. The description fields of Segment2Handle though are preserved in the result.

    • outersect
    • The resultant segment/s, if any, define the area of Sement2Handle that is not common with Segment1Handle. That is, Segment1Handle will take a bite out of Segment2Handle. The geometry of the result is dependent upon the order in which the segments are used with the outersect operation. The description fields of Segment2Handle though are preserved in the result.

    • union
    • The resultant segment/s, if any, define the union of the two segments. That is, the area of both the unioning and unioned segment are represented in the resultant segments. The geometry of the result is identical regardless of the order in which the segments are used with the intersect operation. The description fields of Segment2Handle though are preserved in the result.

  • Segment2Handle
  • Pass by value. The handle to the segment that is sometimes referred to as the interected, outersected or unioned segment. The segment must be closed.

  • ResultSwaHandle
  • Pass by value. The handle to the Swa to which the resultant segments, if any, will be saved.

  • ResultStringId
  • Pass by value. The string number that will be assigned to the resultant segments, if any.

Returns

SCL_OK if the operation was performed successfully. A TCL error is thrown if the requested operation could not be performed or if either of the segments is open or if the operation is invalid.

The geometric operation is sensitive to the geometric relationship of the two segments to each other. For example, applying any operation to segments that are geometrically identical is nonsensical and will most likely result in a TCL error being thrown. There are numerous other contrived geometric circumstances that will prevent a successful result. However, in the general case the operations can be performed successfully.

Examples

# create a swa to load the source strings and a swa for the result strings
SclCreateSwa SwaHandle IntersectionStrings
SclCreateSwa ResultSwaHandle IntersectionResults
# load the source strings
$SwaHandle SclSwaOpenFile intersect1.str
# get handles to the 2 source segments
$SwaHandle SclCreateString StringHandle 1
$StringHandle SclCreateSegment Segment1Handle 0
$StringHandle SclCreateSegment Segment2Handle 1
# do the intersection and save the result
SclIntersectSegments $Segment1Handle intersect $Segment2Handle $ResultSwaHandle 5
$ResultSwaHandle SclSwaSaveStringFile "intersectresult1.str"
SclDestroy ResultSwaHandle
# create the result swa, do the outersection and save the result
SclCreateSwa ResultSwaHandle IntersectionResults
SclIntersectSegments $Segment1Handle outersect $Segment2Handle $ResultSwaHandle 4
$ResultSwaHandle SclSwaSaveStringFile "outersectresult1.str"
SclDestroy ResultSwaHandle
# create the result swa, do the union and save the result
SclCreateSwa ResultSwaHandle IntersectionResults
SclIntersectSegments $Segment1Handle union $Segment2Handle $ResultSwaHandle 3
$ResultSwaHandle SclSwaSaveStringFile "unionresult1.str"
# destroy the result swa
SclDestroy ResultSwaHandle
# now destroy the source swa
SclDestroy SwaHandle