cancel
Showing results for 
Search instead for 
Did you mean: 
EN
cancel
Showing results for 
Search instead for 
Did you mean: 
John Edmundson
Participant

ResizeContour

Does anyone have a simple example of using the "ResizeContour" command?  It can be as small as a 10'x10' box that is made 5' larger with the command.  I have been trying to understand the POLYGON OPERATIONS EXTENSION (GDL Reference Guide - page 647) without success. I wish the manual had included a simple example.

 

Thanks

2 Replies 2
rudl
Booster

Don't know that extension but
You could have your poly curve in a twodimensional array and use the following code (created with help oh chatgpt)
and later use the parameter buffer to feed the POLY2

offset the offset you want (constant edge offset)
working_profile is the input array use working_profile = your array before running the sub
profile_off is the output array
profile_off_reset array to clear profile off just in case.

"offsetpoly":

profile_off = profile_off_reset
FOR i = 1 TO nProfile

    IF i = 1 THEN
        ip = nProfile
    ELSE
        ip = i - 1
    ENDIF

    IF i = nProfile THEN
        in = 1
    ELSE
        in = i + 1
    ENDIF

    ! --------------------------------------------------------
    ! EDGE 1: previous -> current
    ! --------------------------------------------------------

    dx1 = profile_working[i][1] - profile_working[ip][1]
    dy1 = profile_working[i][2] - profile_working[ip][2]

    len1 = SQR(dx1 * dx1 + dy1 * dy1)

    nx1 =  dy1 / len1
    ny1 = -dx1 / len1


    ! --------------------------------------------------------
    ! EDGE 2: current -> next
    ! --------------------------------------------------------

    dx2 = profile_working[in][1] - profile_working[i][1]
    dy2 = profile_working[in][2] - profile_working[i][2]

    len2 = SQR(dx2 * dx2 + dy2 * dy2)

    nx2 =  dy2 / len2
    ny2 = -dx2 / len2


    ! --------------------------------------------------------
    ! POINTS ON THE TWO OFFSET LINES
    ! --------------------------------------------------------

    x1 = profile_working[i][1] - nx1 * offset
    y1 = profile_working[i][2] - ny1 * offset

    x2 = profile_working[i][1] - nx2 * offset
    y2 = profile_working[i][2] - ny2 * offset


    ! --------------------------------------------------------
    ! INTERSECTION
    ! --------------------------------------------------------

    denom = dx1 * dy2 - dy1 * dx2

    IF ABS(denom) > 0.000001 THEN

        t = ((x2 - x1) * dy2 - (y2 - y1) * dx2) / denom

        profile_off[i][1] = x1 + t * dx1
        profile_off[i][2] = y1 + t * dy1

    ELSE

        ! Parallel / 180° corner
        profile_off[i][1] = x1
        profile_off[i][2] = y1

    ENDIF

NEXT i
profile_working = profile_working_reset

RETURN

 

John Edmundson
Participant

Thank you.  This certainly achieves the results I was after.  I have been trying to use the "DICTIONARY" (page 647) functions since they seem powerful for POLY objects.  I expanded your code to draw a POLY and offset it, and it produces the results I am looking for. Thank you.  If I can figure out how to use the DICTIONARY function, I will post the solution.

 

Expanded Code for offset POLY

 

!=============================

dim profile_working[][]
dim profile_working_reset [][]
dim profile_off[][]
dim profile_off_reset[][]
!===================================================
nProfile = 5
offset = -2'
!===================================================
profile_working[1][1] = 0'
profile_working[1][2] = 0'

profile_working[2][1] = 10'
profile_working[2][2] = 0'

profile_working[3][1] = 15'
profile_working[3][2] = 5'

profile_working[4][1] = 5'
profile_working[4][2] = 10'

profile_working[5][1] = -3'
profile_working[5][2] = 4'
!===================================================
profile_off = profile_off_reset
FOR i = 1 TO nProfile

IF i = 1 THEN
ip = nProfile
ELSE
ip = i - 1
ENDIF

IF i = nProfile THEN
in = 1
ELSE
in = i + 1
ENDIF
! --------------------------------------------------------
! EDGE 1: previous -> current
! --------------------------------------------------------
dx1 = profile_working[i][1] - profile_working[ip][1]
dy1 = profile_working[i][2] - profile_working[ip][2]

len1 = SQR(dx1 * dx1 + dy1 * dy1)

nx1 = dy1 / len1
ny1 = -dx1 / len1
! --------------------------------------------------------
! EDGE 2: current -> next
! --------------------------------------------------------

dx2 = profile_working[in][1] - profile_working[i][1]
dy2 = profile_working[in][2] - profile_working[i][2]

len2 = SQR(dx2 * dx2 + dy2 * dy2)

nx2 = dy2 / len2
ny2 = -dx2 / len2

! --------------------------------------------------------
! POINTS ON THE TWO OFFSET LINES
! --------------------------------------------------------

x1 = profile_working[i][1] - nx1 * offset
y1 = profile_working[i][2] - ny1 * offset

x2 = profile_working[i][1] - nx2 * offset
y2 = profile_working[i][2] - ny2 * offset

! --------------------------------------------------------
! INTERSECTION
! --------------------------------------------------------
denom = dx1 * dy2 - dy1 * dx2

IF ABS(denom) > 0.000001 THEN

t = ((x2 - x1) * dy2 - (y2 - y1) * dx2) / denom

profile_off[i][1] = x1 + t * dx1
profile_off[i][2] = y1 + t * dy1

ELSE

! Parallel / 180° corner
profile_off[i][1] = x1
profile_off[i][2] = y1

ENDIF

NEXT i

profile_working = profile_working_reset
! Base Poly ===================================================
poly2 5, 1+4,
profile_working[1][1], profile_working[1][2],
profile_working[2][1], profile_working[2][2],
profile_working[3][1], profile_working[3][2],
profile_working[4][1], profile_working[4][2],
profile_working[5][1], profile_working[5][2]
! Offset Poly ===================================================
poly2 5, 1+4,
profile_off[1][1], profile_off[1][2],
profile_off[2][1], profile_off[2][2],
profile_off[3][1], profile_off[3][2],
profile_off[4][1], profile_off[4][2],
profile_off[5][1], profile_off[5][2]
!===================================================

image.png

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!

Video Thumbnail